On 8/29/25 10:31 AM, Martin D Kealey wrote:
On Thu, 28 Aug 2025, 04:20 Chet Ramey, <chet.ra...@case.edu <mailto:chet.ra...@case.edu>> wrote:It was in early drafts of POSIX.2 (1003.2-1992). The feature started out as the compound command ((expr)) (draft 8), evolved into a word expansion $[...] (draft 9), and then changed to $((...)) (draft 11, the version I have was published in September, 1991).In hindsight, that was an unfortunate decision by the POSIX committee, creating a permanent mess parsing $((…)) as both command and numeric substitutions, depending on what's inside, like $((…)…(…)) or $(((case $thing in *$pattern) /bin/true & esac)).
There was existing practice, since ksh88 had already implemented $((...)).
What was the rationale for preferring $((…)) over $[…] back when they had a free choice?
See if the POSIX rationale answers your question. https://pubs.opengroup.org/onlinepubs/9799919799/xrat/V4_xcu_chap01.html#tag_23_02_06_04
POSIX has a warning tor effect that writing a command substitution starting with $(( is inadvisable, but not formally deprecated (in favour of $( (…)) with whitespace); would there be any appetite for issuing a formal deprecation?
No. POSIX has made this an application requirement and specified that arithmetic evaluation takes precedence. "A conforming application shall ensure that it separates the "$(" and '(' into two tokens (that is, separate them with white space) in a command substitution that starts with a subshell." If the application is non-conforming, all bets are off. The standard requires the shell to parse the contents of the $((...)) as an arithmetic expression, only treating it as a command substitution containing a subshell command if that fails. Shells approach that with differing levels of rigor. POSIX doesn't really `deprecate' things. It removes things from the standard, or makes certain behavior explicitly unspecified, which means shells are allowed to do what they want. Anything that is not in the standard is unspecified. -- ``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/
OpenPGP_signature.asc
Description: OpenPGP digital signature