On Thu, Jun 22, 2000 at 05:25:06PM +1000, Cameron Simpson wrote:
> | > 1. if [ -n $dirname ] && [ \( -d $dirname \) -a \( -x $dirname \) ];
> | > then
> | > 2. if [ -n $dirname ] && [ -d $dirname ] && [ -x $dirname ]; then
> 
> Well, it's only worth it for expensive tests or tests when some depend
> on success of others.

Actually, it's a good habit to use &&/|| in place of -a/-o for the reason
below.

> | Also, to use -a safely you have to put in those ugly
> | brackets :)
> 
> Not so. They're only needed if you have precedence issues, which don't
> obtains in the examples cited.

Consider "$dirname" := "=", and we had

[ -d $dirname -a -x $dirname ]

Since = has the highest precedence among all operators, this becomes

[ \( -d = -a \) -d = ]

which causes an error.

This can be avoided by either using brackets or &&.
-- 
Debian GNU/Linux 2.1 is out! ( http://www.debian.org/ )
Email:  Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text

Reply via email to