Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

"[[" (Re: PATCH: _urls again (Re: setopt localoptions noautoremoveslash))



On Oct 16, 10:56pm, Tanaka Akira wrote:
} Subject: Re: PATCH: _urls again (Re: setopt localoptions noautoremoveslash
}
} In article <38074889.6DCA13F@xxxxxxxxxxxxx>,
}   Oliver Kiddle <opk@xxxxxxxxxxxxx> writes:
} > 
} > > * Use [[ ... ]] instead of [ ... ].
} > 
} > Could someone please explain why [[ ... ]] seems to be prefered where
} > both forms provide the same functionality ? Sven also changed my use of
} > [ -d ... ] to use the double square brackets. Is it faster or something?
} 
} I'm not sure about this.  But I believe the description of `test' in
} zshbuiltins(1).

PWS says in http://www.ifh.de/~pws/computing/zshguide02.html#l6

    Second aside for users of sh: you may remember that tests in sh used
    a single pair of brackets, `if [ ... ]; then ...', or equivalently
    as a command called test, `if test ...; then ...'. The Korn shell
    was deliberately made to be different, and zsh follows that. The
    reason is that `[[' is treated specially, which allows the shell to
    do some extra checks and allows more natural syntax. For example,
    you may know that in sh it's dangerous to test a parameter which
    may be empty: `[ $var = foo ]' will fail if $var is empty, because
    the word is missed out and the shell never knows it was supposed
    to be there (I'll explain about parameters shortly); with `[[ ...
    ]]', this is quite safe because the shell is aware there's a word
    before the `=', even if it's empty. Also, you can use `&&' and
    `||' to mean logical `and' and `or', which agrees with the usual
    UNIX/C convention; in sh, they would have been taken as starting a
    new command, not as part of the test, and you have to use the less
    clear `-a' and `-o'. Actually, zsh provides the old form of test for
    backward compatibility, but things will work a lot more smoothly if
    you don't use it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author