bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem around brackets, && and ||


From: Marc Herbert
Subject: Re: Problem around brackets, && and ||
Date: Tue, 04 May 2010 13:05:24 +0100
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4

Le 03/05/2010 21:08, Kunszt Árpád a écrit :

>> http://mywiki.wooledge.org/BashPitfalls#cmd1_.26.26_cmd2_.7C.7C_cmd3
  
> I read it, thanks. I understand it now.
> 
> I read man bash lots of times, but this behavior had escaped my
> attention. There isn't any word about cmd1 && cmd2 || cmd3 only the cmd1
> && cmd2 and cmd1 || cmd2 mentioned. I think lots of people, including
> myself, thought that && and || is an equivalent to the if ... then ...
> else statement.

Out of curiosity, what made you think that?

I find the following quite intuitive:

   true && false || this_cmd_is_run


"true && false" is obviously equal to "false".



> So my bugreport is now against the documentation. :-)

This is already documented. Excerpts from the "List of Commands"
section:

*) "AND and OR lists are executed with left associativity"

Applied here:
   cmdA && cmdB || cmdC   <=>   { cmdA && cmdB ; } || cmdC


*) "The return status of AND and OR lists is the exit status of the
  last command executed in the list"

Applied here:   
    Whenever cmdB is run and fails, "{ cmdA && cmdB ; }" is
    considered to have failed  (and cmdC is run)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]