[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How come math/arithmetic cannot work by set -x
From: |
Chet Ramey |
Subject: |
Re: How come math/arithmetic cannot work by set -x |
Date: |
Sat, 13 Aug 2022 12:50:35 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 |
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 chet@case.edu http://tiswww.cwru.edu/~chet/