From: bsh on
Rakesh Sharma <sharma...(a)hotmail.com> wrote:
> bsh <brian_hi...(a)rocketmail.com> wrote:
> > Rakesh Sharma <sharma...(a)hotmail.com> wrote:
> > > Parmenides <mobile.parmeni...(a)gmail.com> wrote:

> > Why? "-a" within at least the "[[ ... ]]" test condition is
> > equivalent to "&&" and will be decomposed to "[[ ... ]]
> > && [[ ... ]] ...", ....
> > ...
> Why? because they are syntax in error that's why.

> e.g., if you replace a '&&' with '-a' in the
>    if [ $dirname = $PWD ] && [ -z "$DIR_STACK" ]; then
>
> you get
>
> if [ $dirname = $PWD ] -a [ -z "$DIR_STACK" ]; then
>
> which is not a valid shell syntax.

Oh, I see. Scanning the original code again, I see:

if [ \( -d $dirname \) -a \( -x $dirname \) ]; then

.... and you were exclaiming upon the interstitial "-a" being
not equivalent to logical AND ("&&").

In ksh the new test builtin command "[[" is preferred over the
deprecated old "[" command... and for good reasons -- the POSIX
document. What I was thinking was to use entirely the new
form and not use at all an "-a" anywhere, inside _or_ outside
of the test command.

if [[ -d $dirname && -x $dirname ]]

So we are both right.

=Brian



First  |  Prev  | 
Pages: 1 2
Prev: why is echo different?
Next: unpack a gz file