help-bash
[Top][All Lists]
Advanced

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

Re: Is it really necessary to allow operators and whole right hand sides


From: Chet Ramey
Subject: Re: Is it really necessary to allow operators and whole right hand sides to be substituted in (())?
Date: Tue, 18 May 2021 09:44:39 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1

On 5/17/21 10:08 PM, Lawrence Velázquez wrote:

a=4
b=a
c=b
((d = c * 2))
echo "$d"    # output: 8

Also, is there a real situation such multi-level reference is really
useful.

What alternative would you prefer?  That ((d = c * 2)) resolve to
((d = b * 2)), treat b as 0, and set d to 0?  That it consider "b"
an error?  Or what?

That's the POSIX solution. POSIX says that you only have to expand a token
that looks like a variable if its value looks like an integer constant, and
are permitted to throw an error otherwise. It doesn't require treating the
value as an expression, though it does not forbid it. Those semantics
simplify the implementation, but not very much, at the cost of flexibility.

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