Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [[ and [
On Tue, 6 Mar 2012 15:05:41 +0400
sergio <mailbox@xxxxxxxxxxxxx> wrote:
> On 03/06/2012 10:05 AM, Bart Schaefer wrote:
>
> What was the reason to implement [[ ]]? What advantages it gives? As
> I see [[ ]] and [ ] provides same features.
[[ ... ]] is specially parsed: this gives better error checking and an
assurance that each argument means what you think it does.
Consider:
foo=
[ $foo -eq "" ]
With normal shell behaviour, this turns into the arguments "[", "-eq",
"]", which confuses the test command. This is why you see all those
"x"s and double quotes in configure scripts. However,
[[ $foo -eq "" ]]
does exactly what it looks like it does because "[[" is special to the
shell and it looks at the raw arguments to parse the syntax.
Generally, I get the impression Bourne shell syntax was something of a
leap in the dark at the time; if you were designing it from scratch now,
it would look considerably different in a lot of ways.
--
Peter Stephenson <pws@xxxxxxx> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog
Messages sorted by:
Reverse Date,
Date,
Thread,
Author