* [[ and [ @ 2012-03-04 2:36 sergio 2012-03-04 4:24 ` Bart Schaefer 2012-03-04 4:50 ` Kurtis Rader 0 siblings, 2 replies; 22+ messages in thread From: sergio @ 2012-03-04 2:36 UTC (permalink / raw) To: zsh-users Hello. It's dumb question, but I can't find this in man. What it the difference between [[ ]] and [ ]? if [[ ]]; then ... fi and if [ ]; than ... fi OK, the first is an evaluating of the conditional expression, and what is the second? -- sergio. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-04 2:36 [[ and [ sergio @ 2012-03-04 4:24 ` Bart Schaefer 2012-03-06 0:32 ` sergio 2012-03-04 4:50 ` Kurtis Rader 1 sibling, 1 reply; 22+ messages in thread From: Bart Schaefer @ 2012-03-04 4:24 UTC (permalink / raw) To: zsh-users On Mar 4, 6:36am, sergio wrote: } } if [[ ]]; then ... fi } and } if [ ]; than ... fi } } OK, the first is an evaluating of the conditional expression, and what } is the second? An alias for the "test" builtin -- so everything that follows "[" is parsed/expanded like an ordinary command argument. It's in the zsh manual under the "test" command description. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-04 4:24 ` Bart Schaefer @ 2012-03-06 0:32 ` sergio 2012-03-06 6:05 ` Bart Schaefer 0 siblings, 1 reply; 22+ messages in thread From: sergio @ 2012-03-06 0:32 UTC (permalink / raw) To: zsh-users On 03/04/2012 08:24 AM, Bart Schaefer wrote: May be all [ ] should be changed to [[ ]] in zsh distribution if it's more native way? % grep -R 'if \[[^\[]' /usr/share/zsh/* | wc -l 35 -- sergio. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 0:32 ` sergio @ 2012-03-06 6:05 ` Bart Schaefer 2012-03-06 11:05 ` sergio 0 siblings, 1 reply; 22+ messages in thread From: Bart Schaefer @ 2012-03-06 6:05 UTC (permalink / raw) To: zsh-users On Mar 6, 4:32am, sergio wrote: } } May be all [ ] should be changed to [[ ]] in zsh distribution if it's } more native way? There may be some that could be changed, but they do have different parsing rules so they aren't necessarily interchangable. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 6:05 ` Bart Schaefer @ 2012-03-06 11:05 ` sergio 2012-03-06 11:35 ` Peter Stephenson 2012-03-07 8:12 ` Nadav Har'El 0 siblings, 2 replies; 22+ messages in thread From: sergio @ 2012-03-06 11:05 UTC (permalink / raw) To: zsh-users 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. -- sergio. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:05 ` sergio @ 2012-03-06 11:35 ` Peter Stephenson 2012-03-06 11:44 ` Peter Stephenson 2012-03-06 16:16 ` sergio 2012-03-07 8:12 ` Nadav Har'El 1 sibling, 2 replies; 22+ messages in thread From: Peter Stephenson @ 2012-03-06 11:35 UTC (permalink / raw) To: zsh-users On Tue, 6 Mar 2012 15:05:41 +0400 sergio <mailbox@sergio.spb.ru> 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@csr.com> 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 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:35 ` Peter Stephenson @ 2012-03-06 11:44 ` Peter Stephenson 2012-03-06 11:53 ` Mikael Magnusson 2012-03-07 8:52 ` Nadav Har'El 2012-03-06 16:16 ` sergio 1 sibling, 2 replies; 22+ messages in thread From: Peter Stephenson @ 2012-03-06 11:44 UTC (permalink / raw) To: zsh-users On Tue, 6 Mar 2012 11:35:32 +0000 Peter Stephenson <Peter.Stephenson@csr.com> wrote: > However, > > [[ $foo -eq "" ]] > > does exactly what it looks like it does Sigh. Sort of. [ ... -eq ...] and [[ ... -eq ... ]] are numeric tests, so if foo is a string of zeros it's not doing what it looks like. I should have said [ $foo = "" ]] and [[ $foo = "" ]] or [[ $foo == "" ]] I don't know why it's that way round, it seems a bit illogical (which is why Perl is the other way), but it always has been that way. -- Peter Stephenson <pws@csr.com> 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 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:44 ` Peter Stephenson @ 2012-03-06 11:53 ` Mikael Magnusson 2012-03-07 9:02 ` Nadav Har'El 2012-03-07 8:52 ` Nadav Har'El 1 sibling, 1 reply; 22+ messages in thread From: Mikael Magnusson @ 2012-03-06 11:53 UTC (permalink / raw) To: Peter Stephenson; +Cc: zsh-users On 6 March 2012 12:44, Peter Stephenson <Peter.Stephenson@csr.com> wrote: > On Tue, 6 Mar 2012 11:35:32 +0000 > Peter Stephenson <Peter.Stephenson@csr.com> wrote: >> However, >> >> [[ $foo -eq "" ]] >> >> does exactly what it looks like it does > > Sigh. Sort of. [ ... -eq ...] and [[ ... -eq ... ]] are numeric tests, > so if foo is a string of zeros it's not doing what it looks like. I > should have said > > [ $foo = "" ]] > > and > > [[ $foo = "" ]] > > or > > [[ $foo == "" ]] > > I don't know why it's that way round, it seems a bit illogical (which is > why Perl is the other way), but it always has been that way. Incidentally, this is probably the most confusing error message ever, % [ $foo == "" ] zsh: = not found -- Mikael Magnusson ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:53 ` Mikael Magnusson @ 2012-03-07 9:02 ` Nadav Har'El 2012-03-07 9:05 ` Mikael Magnusson 0 siblings, 1 reply; 22+ messages in thread From: Nadav Har'El @ 2012-03-07 9:02 UTC (permalink / raw) To: Mikael Magnusson; +Cc: Peter Stephenson, zsh-users On Tue, Mar 06, 2012, Mikael Magnusson wrote about "Re: [[ and [": > Incidentally, this is probably the most confusing error message ever, > % [ $foo == "" ] > zsh: = not found I see something slightly different. On zsh 4.3.15, with unset $foo, I get: $ [ $foo == "" ] zsh: parse error: condition expected: == Which indeed is not very clear, but arguably not "the most confusing error message ever" ;-) To compare, GNU test shows this: $ /usr/bin/[ $foo == "" ] /usr/bin/[: missing argument after `' Bash shows: $ [ $foo == "" ] bash: [: ==: unary operator expected Ksh shows $ [ $foo == "" ] ksh: [: argument expected I'm not sure which is clearest, probably ksh's. If it were up to me, I'd say something like: $ [ $foo == "" ] zsh: parse error: ==: missing first argument. -- Nadav Har'El | Wednesday, Mar 7 2012, nyh@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |A language is a dialect with an army. http://nadav.harel.org.il | ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 9:02 ` Nadav Har'El @ 2012-03-07 9:05 ` Mikael Magnusson 2012-03-07 9:21 ` Nadav Har'El 0 siblings, 1 reply; 22+ messages in thread From: Mikael Magnusson @ 2012-03-07 9:05 UTC (permalink / raw) To: Nadav Har'El; +Cc: Peter Stephenson, zsh-users On 7 March 2012 10:02, Nadav Har'El <nyh@math.technion.ac.il> wrote: > On Tue, Mar 06, 2012, Mikael Magnusson wrote about "Re: [[ and [": >> Incidentally, this is probably the most confusing error message ever, >> % [ $foo == "" ] >> zsh: = not found > > I see something slightly different. On zsh 4.3.15, with unset $foo, I > get: > > $ [ $foo == "" ] > zsh: parse error: condition expected: == > > Which indeed is not very clear, but arguably not "the most confusing > error message ever" ;-) You need to not have done unsetopt equals to see the confusing one :). -- Mikael Magnusson ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 9:05 ` Mikael Magnusson @ 2012-03-07 9:21 ` Nadav Har'El 2012-03-07 15:27 ` Bart Schaefer 0 siblings, 1 reply; 22+ messages in thread From: Nadav Har'El @ 2012-03-07 9:21 UTC (permalink / raw) To: Mikael Magnusson; +Cc: Peter Stephenson, zsh-users On Wed, Mar 07, 2012, Mikael Magnusson wrote about "Re: [[ and [": > > On Tue, Mar 06, 2012, Mikael Magnusson wrote about "Re: [[ and [": > >> Incidentally, this is probably the most confusing error message ever, > >> % [ $foo == "" ] > >> zsh: = not found > > > > I see something slightly different. On zsh 4.3.15, with unset $foo, I >.. > You need to not have done unsetopt equals to see the confusing one :). Wow, it's not just EQUALS (which I do have set, and use it all the time), it's also the NOMATCH option which I forgot was the default. I've mentioned this in the past that I think that NONOMATCH should be the default... With NONOMATCH, I get: $ echo =ls /bin/ls $ echo =dog =dog $ echo == == $ [ a == a ] && echo success success which is exactly what I would expect. With the (unfortunately default) NOMATCH, I get: $ echo =ls /bin/ls $ echo =dog zsh: dog not found $ echo == zsh: = not found $ [ a == a ] && echo success zsh: = not found So the confusing error doesn't come from [, it comes from NOMATCH, which (did I say that? :-)) I really don't like being the default. One thing to note, though, is that the traditional equality operator for test (or '[') was "=", not "==", so had you used =, you would not have this problem in the first place... -- Nadav Har'El | Wednesday, Mar 7 2012, nyh@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |Topologist, n.: A person who cannot tell http://nadav.harel.org.il |a doughnut from a coffee mug. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 9:21 ` Nadav Har'El @ 2012-03-07 15:27 ` Bart Schaefer 0 siblings, 0 replies; 22+ messages in thread From: Bart Schaefer @ 2012-03-07 15:27 UTC (permalink / raw) To: zsh-users On Mar 7, 11:21am, Nadav Har'El wrote: } } Wow, it's not just EQUALS (which I do have set, and use it all the time), } it's also the NOMATCH option which I forgot was the default. I've mentioned } this in the past that I think that NONOMATCH should be the default... Everybody has different preferences; there's no default we can choose about which someone wouldn't complain. NO_MATCH is the default for the simple reason that Zsh was designed to act like csh at the prompt for people who preferred Bourne shell's more cleanly defined syntax, and nomatch is the default in csh. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:44 ` Peter Stephenson 2012-03-06 11:53 ` Mikael Magnusson @ 2012-03-07 8:52 ` Nadav Har'El 2012-03-07 9:43 ` Peter Stephenson 1 sibling, 1 reply; 22+ messages in thread From: Nadav Har'El @ 2012-03-07 8:52 UTC (permalink / raw) To: Peter Stephenson; +Cc: zsh-users On Tue, Mar 06, 2012, Peter Stephenson wrote about "Re: [[ and [": > On Tue, 6 Mar 2012 11:35:32 +0000 > Sigh. Sort of. [ ... -eq ...] and [[ ... -eq ... ]] are numeric tests, > so if foo is a string of zeros it's not doing what it looks like. I > should have said > > [ $foo = "" ]] >... > I don't know why it's that way round, it seems a bit illogical (which is > why Perl is the other way), but it always has been that way. In addition to being the way it's always been, it makes even more sense when you consider the newer features of ksh (and following it, zsh and bash). In ksh, arithmetic expressions got a new syntax, ((. If if you would like to check for arithmetic equality (or whatever), you'd most likely use if (( $foo == 2 )) or even better, without the "$": if (( foo == 2 )) The new (( can of course do much more interesting arithmetic expressions, e.g.: if (( foo+1 < bar/2.0 )) Then, test, [, or [[ remain useful only for *strings*. So it makes sense for their ==, <, etc., to be geared for comparing strings. Ksh even considers "-eq", "-gt" to be obsolete - if you're using them, you should probably be using (( instead. The zsh manual does not state that "-eq" and the rest are obsolete (in Conditional Expressions), but maybe it should: Ksh added this statement to its manual in 1993, after it was absent in 1998: Compare http://www.research.att.com/sw/download/man/man1/ksh88.html http://www.research.att.com/sw/download/man/man1/ksh.html -- Nadav Har'El | Wednesday, Mar 7 2012, nyh@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |Live as if you were to die tomorrow, http://nadav.harel.org.il |learn as if you were to live forever. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 8:52 ` Nadav Har'El @ 2012-03-07 9:43 ` Peter Stephenson 2012-03-07 14:11 ` Nadav Har'El 0 siblings, 1 reply; 22+ messages in thread From: Peter Stephenson @ 2012-03-07 9:43 UTC (permalink / raw) To: zsh-users On Wed, 7 Mar 2012 10:52:36 +0200 Nadav Har'El <nyh@math.technion.ac.il> wrote: > The zsh manual does not state that "-eq" and the rest are obsolete (in > Conditional Expressions), but maybe it should: Actually, I don't consider them obsolete. I prefer [[ $n -gt 1 && $m == foo ]] to the rather cluttered (( n > 1 )) && [[ $m == foo ]] There's no gain in us getting rid of them anyway, so declaring them obsolete is confusing people (we've had this with similar features there's no point in removing). -- Peter Stephenson <pws@csr.com> 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 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 9:43 ` Peter Stephenson @ 2012-03-07 14:11 ` Nadav Har'El 2012-03-07 14:27 ` Peter Stephenson 2012-03-07 18:38 ` Mark 0 siblings, 2 replies; 22+ messages in thread From: Nadav Har'El @ 2012-03-07 14:11 UTC (permalink / raw) To: Peter Stephenson; +Cc: zsh-users On Wed, Mar 07, 2012, Peter Stephenson wrote about "Re: [[ and [": > On Wed, 7 Mar 2012 10:52:36 +0200 > Nadav Har'El <nyh@math.technion.ac.il> wrote: > > The zsh manual does not state that "-eq" and the rest are obsolete (in > > Conditional Expressions), but maybe it should: >... > > There's no gain in us getting rid of them anyway, so declaring them > obsolete is confusing people (we've had this with similar features > there's no point in removing). Well, I agree that -eq and friends will never be removed - they existed for at least 33 years now (since 7th edition Unix), so let them stay another 30 years ;-)). But people who read the manual can be told that there is a newer alternative, namely ((. Also, like I said, zsh's inspiration for the '[[' command, ksh, already declared 20 years ago that these options are obsolete. Anyway, it was you who said these -eq et al. were confusing :-) -- Nadav Har'El | Wednesday, Mar 7 2012, nyh@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |You have the right to remain silent. http://nadav.harel.org.il |Anything you say will be used against you. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 14:11 ` Nadav Har'El @ 2012-03-07 14:27 ` Peter Stephenson 2012-03-07 18:38 ` Mark 1 sibling, 0 replies; 22+ messages in thread From: Peter Stephenson @ 2012-03-07 14:27 UTC (permalink / raw) To: zsh-users On Wed, 7 Mar 2012 16:11:22 +0200 Nadav Har'El <nyh@math.technion.ac.il> wrote: > Well, I agree that -eq and friends will never be removed - they existed for > at least 33 years now (since 7th edition Unix), so let them stay another 30 > years ;-)). But people who read the manual can be told that there is a > newer alternative, namely ((. That's true. > Anyway, it was you who said these -eq et al. were confusing :-) I like confusing myself, it's one of the ways I know both I and the world still exist. Index: Doc/Zsh/cond.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/cond.yo,v retrieving revision 1.10 diff -p -u -r1.10 cond.yo --- Doc/Zsh/cond.yo 24 Oct 2011 15:35:14 -0000 1.10 +++ Doc/Zsh/cond.yo 7 Mar 2012 14:24:09 -0000 @@ -151,6 +151,11 @@ based on ASCII value of their characters ) item(var(exp1) tt(-eq) var(exp2))( true if var(exp1) is numerically equal to var(exp2). +Note that for purely numeric comparisons use of the +tt(LPAR()LPAR())var(...)tt(RPAR()RPAR()) builtin described in +ifzman(the section `ARITHMETIC EVALUATION')\ +ifnzman(noderef(Arithmetic Evaluation)) is more convenient than +conditional expressions. ) item(var(exp1) tt(-ne) var(exp2))( true if var(exp1) is numerically not equal to var(exp2). -- Peter Stephenson <pws@csr.com> 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 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-07 14:11 ` Nadav Har'El 2012-03-07 14:27 ` Peter Stephenson @ 2012-03-07 18:38 ` Mark 1 sibling, 0 replies; 22+ messages in thread From: Mark @ 2012-03-07 18:38 UTC (permalink / raw) To: zsh-users > But people who read the manual can be told that there is a > newer alternative, namely ((. They should also be very aware that (( 0 )) returns false and (( "not 0" )) returns true. Try it: (( 0 )) && echo foobar ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:35 ` Peter Stephenson 2012-03-06 11:44 ` Peter Stephenson @ 2012-03-06 16:16 ` sergio 2012-03-06 16:29 ` Peter Stephenson 1 sibling, 1 reply; 22+ messages in thread From: sergio @ 2012-03-06 16:16 UTC (permalink / raw) To: zsh-users Peter, than you for a good explanation. Hope you'll add it to the manual. -- sergio. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 16:16 ` sergio @ 2012-03-06 16:29 ` Peter Stephenson 2012-03-06 17:40 ` sergio 0 siblings, 1 reply; 22+ messages in thread From: Peter Stephenson @ 2012-03-06 16:29 UTC (permalink / raw) To: zsh-users On Tue, 6 Mar 2012 20:16:32 +0400 sergio <mailbox@sergio.spb.ru> wrote: > than you for a good explanation. Hope you'll add it to the manual. Actually, the description of test and [ already has this to say... test [ arg ... ] [ [ arg ... ] ] Like the system version of test. Added for compatibility; use conditional expressions instead (see the section `Conditional Expressions'). The main differences between the conditional expression syntax and the test and [ builtins are: these com‐ mands are not handled syntactically, so for example an empty variable expansion may cause an argument to be omitted; syntax errors cause status 2 to be returned instead of a shell error; and arithmetic operators expect integer arguments rather than arithmetic expressions. The command attempts to implement POSIX and its extensions where these are specified. Unfortunately there are intrinsic ambigui‐ ties in the syntax; in particular there is no distinction between test operators and strings that resemble them. The standard attempts to resolve these for small numbers of argu‐ ments (up to four); for five or more arguments compatibility cannot be relied on. Users are urged wherever possible to use the `[[' test syntax which does not have these ambiguities. -- Peter Stephenson <pws@csr.com> 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 ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 16:29 ` Peter Stephenson @ 2012-03-06 17:40 ` sergio 0 siblings, 0 replies; 22+ messages in thread From: sergio @ 2012-03-06 17:40 UTC (permalink / raw) To: zsh-users On 03/06/2012 08:29 PM, Peter Stephenson wrote: > Actually, the description of test and [ already has this to say... Sorry, my fault. -- sergio. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-06 11:05 ` sergio 2012-03-06 11:35 ` Peter Stephenson @ 2012-03-07 8:12 ` Nadav Har'El 1 sibling, 0 replies; 22+ messages in thread From: Nadav Har'El @ 2012-03-07 8:12 UTC (permalink / raw) To: sergio; +Cc: zsh-users On Tue, Mar 06, 2012, sergio wrote about "Re: [[ and [": > 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. In the original Unix, "[" was not a shell builtin - it was a normal program, /bin/[, normally a hard link to /bin/test. As such, you needed to follow ordinary (and annoying) quoting rules for its parameters. When ksh (and later zsh and bash) implemented '[' as a builtin, it retained its exact old behavior for backward compatibility, this should NOT and instead invented a new syntax, the [[, for an improved version, with less need for quoting and new tests, including for example the "<" operator for text dictionary-order (on why this deals with text and not numbers, see my separate reply). -- Nadav Har'El | Wednesday, Mar 7 2012, nyh@math.technion.ac.il |----------------------------------------- Phone +972-523-790466, ICQ 13349191 |Linux: Because a PC is a terrible thing http://nadav.harel.org.il |to waste. ^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [[ and [ 2012-03-04 2:36 [[ and [ sergio 2012-03-04 4:24 ` Bart Schaefer @ 2012-03-04 4:50 ` Kurtis Rader 1 sibling, 0 replies; 22+ messages in thread From: Kurtis Rader @ 2012-03-04 4:50 UTC (permalink / raw) To: sergio; +Cc: zsh-users [-- Attachment #1: Type: text/plain, Size: 1101 bytes --] To expand on Bart's reply the "if [ ]" form goes back to the original Bourne shell (probably before you were born but not before I was born :-) which only supported invoking external programs and evaluating their exit status. The left square-bracket was actually a filesystem alias for /bin/test (or /usr/bin/test). Although today it is more likely that both the "[" and "test" commands are built-ins to the shell that exhibit the historic semantics. Whereas "[[" is a token that triggers the shell to parse the contents up to the matching "]]" using different rules. I believe the "[[ ]]" notation was introduced by the Korn shell after David Korn who wrote the first version. On Sat, Mar 3, 2012 at 6:36 PM, sergio <mailbox@sergio.spb.ru> wrote: > Hello. > > It's dumb question, but I can't find this in man. > > What it the difference between [[ ]] and [ ]? > if [[ ]]; then ... fi > and > if [ ]; than ... fi > > OK, the first is an evaluating of the conditional expression, and what > is the second? > > -- > sergio. > -- Kurtis Rader Caretake of the exceptional canines Einstein and Chino ^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2012-03-07 18:46 UTC | newest] Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-03-04 2:36 [[ and [ sergio 2012-03-04 4:24 ` Bart Schaefer 2012-03-06 0:32 ` sergio 2012-03-06 6:05 ` Bart Schaefer 2012-03-06 11:05 ` sergio 2012-03-06 11:35 ` Peter Stephenson 2012-03-06 11:44 ` Peter Stephenson 2012-03-06 11:53 ` Mikael Magnusson 2012-03-07 9:02 ` Nadav Har'El 2012-03-07 9:05 ` Mikael Magnusson 2012-03-07 9:21 ` Nadav Har'El 2012-03-07 15:27 ` Bart Schaefer 2012-03-07 8:52 ` Nadav Har'El 2012-03-07 9:43 ` Peter Stephenson 2012-03-07 14:11 ` Nadav Har'El 2012-03-07 14:27 ` Peter Stephenson 2012-03-07 18:38 ` Mark 2012-03-06 16:16 ` sergio 2012-03-06 16:29 ` Peter Stephenson 2012-03-06 17:40 ` sergio 2012-03-07 8:12 ` Nadav Har'El 2012-03-04 4:50 ` Kurtis Rader
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).