On 8/12/22 8:22 PM, Dennis Williamson wrote:

set -x; unset a; b=2; c=7; ((a = b + c)); echo "$a $b $c"; set +x

+ unset a
+ b=2
+ c=7
+ (( a = b + c ))
+ echo '9 2 7'
9 2 7
+ set +x

without the dollar signs doesn't.

"Within an expression, shell
 variables  may  also  be referenced by name without using the parameter
 expansion syntax.  A shell variable that is null or unset evaluates  to
 0 when referenced by name without using the parameter expansion syntax.
 The value of a variable is evaluated as an arithmetic  expression  when
 it  is  referenced"

So this is the behavior of arithmetic expansion (and, as a consequence, the
execution of the `((' command) and `set -x' will not show it. `set -x'
displays the command and its arguments before it is executed.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to