[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SLUG] bash



>>>>> "Minh" == Minh Van <mle@nospam.mail.usyd.edu.au> writes:

Minh> given the expression:
Minh> 1. if [ -n $dirname ] && [ \( -d $dirname \) -a \( -x $dirname \) ];
Minh> then

Minh> in bash, i don't understand why it is any different and less tedious from:

Minh> 2. if [ -n $dirname ] && [ -d $dirname ] && [ -x $dirname ]; then

Minh> could somebody explain the reason or need to have embedded boolean
Minh> constructs and escaped parentheses in the first expression ?

If test is built into your shell (and it is in most modern shells)
then there's no difference.  If you want to be efficient on older
shells, then
use

if [ -n "$dirname" -a -d "$dirname" -a -x "$dirname" ]
then
	...
and spawn only one process to do the testing rather than two or three.

Note the quoting, btw.  Without that, you'd need to split into two
test commands because the second would be syntactically incorrect
otherise ($dirname vanishes if it's zero length, so you end up with
	 [ \( -d \) -a \( -x  \) ]
as the second expression.

The parentheses are superfluous.

Peter c
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to slug-request@nospam.slug.org.au with
unsubscribe in the text