[Top][All Lists]

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

Re: set -u not working as expected

From: Chet Ramey
Subject: Re: set -u not working as expected
Date: Sun, 2 Aug 2020 16:51:26 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

On 8/2/20 3:34 AM, Lawrence Velázquez wrote:

>>> % bash -c 'set -u; typeset -i v; v+=1; printf "<%s>\\n" "$v"'
>>> <1>
>>> % ksh -c 'set -u; typeset -i v; v+=1; printf "<%s>\\n" "$v"'
>>> <1>
>>> % zsh -c 'set -u; typeset -i v; v+=1; printf "<%s>\\n" "$v"'
>>> <1>
> ...which contrasts with the behavior of let. Someone else will have
> to explain this, as I don't know what to make of it.

The integer attribute means the rhs of the assignment operator is
evaluated as an expression. It doesn't mean the assignment is performed
in an arithmetic context, as with `let' or `$((...))'. The special case,
which is done to conform to user expections, is that the result is added
to the current value, if any, instead of being appended like the usual
behavior of `+='. Note that there are no corresponding `name*=value' or
`name-=value' variable assignment operators, and that `-u' isn't in
effect for any use of `+=', whether the integer attribute is present or

``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/

reply via email to

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