[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: |
Lawrence Velázquez |
Subject: |
Re: Is it really necessary to allow operators and whole right hand sides to be substituted in (())? |
Date: |
Mon, 17 May 2021 22:08:52 -0400 |
User-agent: |
Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 |
On Mon, May 17, 2021, at 9:31 PM, Peng Yu wrote:
> I would like to know if this decision is based on any logic reasoning.
You could try asking David Korn.
> But it seems to be more based on convenience of implementation as when
> it is implemented in this way, the implementation for math can be
> partly shared with other parts.
Convenience of implementation is not nothing.
The current state of affairs also maintains consistency with
non-arithmetic contexts (single quotes and literal here-documents
aside).
> The reason that I want to understand the rationale is that things like
> these seem to make shell code inherently hard to optimize for speed,
> because there is no way to know what the expression expands to until
> the code actually runs. If speed were a concern for the math
> operations
It isn't.
> >> 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?
> Just to be sure, `(())` and `let` are not part of POSIX but bash
> extensions of POSIX shell?
As Chet already said, they were introduced by ksh.
--
vq