bug-bash
[Top][All Lists]
Advanced

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

Re: Logical operators in arithmetic evaluation: documentation vs impleme


From: Greg Wooledge
Subject: Re: Logical operators in arithmetic evaluation: documentation vs implementation
Date: Thu, 18 Apr 2013 10:40:43 -0400
User-agent: Mutt/1.4.2.3i

On Thu, Apr 18, 2013 at 11:59:40AM +0200, andras@coolbox.se wrote:
> The ARITHMETIC EVALUATION section of the man page claims equivalence with C
> for all the operators, but in reality bash does not perform short circuit
> evaluation, which implies that the logical operators do NOT produce the same
> results as in C.

You missed this part, under EXPANSION:

      Expansion is performed on the command line after it has been split
      into words.  There are seven kinds of expansion performed: brace
      expansion, tilde expansion, parameter and variable expansion, command
      substitution, arithmetic expansion, word splitting, and pathname
      expansion.

      The order of expansions is: brace expansion, tilde expansion,
      parameter, variable and arithmetic expansion and command substitution
      (done in a left-to-right fashion), word splitting, and pathname
      expansion.

It's not clear from this part of the documentation how bash handles
a command substitution nested inside an arithmetic expansion, but you've
experimentally demonstrated that the nested substitution is performed
first.

Once the nested substitution has been done, short circuit evaluation
DOES take effect.  Here's a demonstration of short circuit without
the nested substitution causing confusion:

imadev:~$ echo $((1/0))
bash: 1/0: division by 0 (error token is "0")
imadev:~$ echo $((0 && 1/0))
0



reply via email to

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