From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7785 invoked from network); 16 Oct 1999 15:45:01 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 16 Oct 1999 15:45:01 -0000 Received: (qmail 20835 invoked by alias); 16 Oct 1999 15:44:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8300 Received: (qmail 20825 invoked from network); 16 Oct 1999 15:44:29 -0000 From: "Bart Schaefer" Message-Id: <991016153346.ZM27414@candle.brasslantern.com> Date: Sat, 16 Oct 1999 15:33:46 +0000 In-Reply-To: Comments: In reply to Tanaka Akira "Re: PATCH: _urls again (Re: setopt localoptions noautoremoveslash)" (Oct 16, 10:56pm) References: <199910151210.OAA18066@beta.informatik.hu-berlin.de> <38074889.6DCA13F@u.genie.co.uk> X-Mailer: Z-Mail (5.0.0 30July97) To: zsh-workers@sunsite.auc.dk Subject: "[[" (Re: PATCH: _urls again (Re: setopt localoptions noautoremoveslash)) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 16, 10:56pm, Tanaka Akira wrote: } Subject: Re: PATCH: _urls again (Re: setopt localoptions noautoremoveslash } } In article <38074889.6DCA13F@u.genie.co.uk>, } Oliver Kiddle 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