[Top][All Lists]

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

Re: doesn't bash do variable subst. or quote removal on function stateme

From: Linda Walsh
Subject: Re: doesn't bash do variable subst. or quote removal on function statement
Date: Wed, 13 Jan 2016 09:20:38 -0800
User-agent: Thunderbird

Chet Ramey wrote:
On 1/12/16 4:33 PM, Linda Walsh wrote:
   But why?  It's less noisy than any alternative.
It's not as if I can type echo $(1+2) and expect it to work.

Because it only ever appeared in a Posix draft standard, and there's no
reason not to use the standard syntax.
   All of the linux security related to capabilities "only" appeared
in a Posix draft standard.  That hasn't stopped it from being adopted in
various forms in many *nix's implementing capabilities.  $() is already
used for command execution and () is already used for expression
grouping.  Putting the two of them together takes  2 operators from 2
disparate areas and claiming it's a new operator vs. using $[] which AFAIK,
isn't used for anything, seems deliberately Machiavellian, not to mention
noisier.  If  both were available as a standard, which would make for
clearer expressions?  I.e. What can $[] be confused with?  V. $() and ()
already having alternate uses, not to mention creating tortured,
ambiguous syntax like:

declare -i a=0;((a=1+2));(echo $(echo $a))

Now if I wanted to do the assignment in the echo, I have to do this?:

declare -i a=0; (echo $(echo $((a=1+2))))   Vs.
declare -i a=0; (echo $(echo $[a=1+2]))

Of course the 2nd form using brackets, w/o the '$'
can be used as an array subscript -- where it gets the same
evaluation.  I.e.

declare -i a=0; (echo $(echo ${ar[a=1+2]})) -- i.e. the language
already uses [] to hold an arithmetic expression for arrays, but you
can't take $((a=1+2)) and use the expression after the $ directly as
an array as in:
declare -i a=0; (echo $(echo ${ar((a=1+2))})) (not that such usage would
be that desirable -- but the point being that [] is already used for
arith evaluation in arrays, so adding the sigil on front for stand-alone
arithmetic evaluation seems to be a logical progression -- Not something
one has with $(()).

It doesn't seem very consistent to choose (()) over [] -- why come up with
a special longer operator for arith eval, when [] was already used for
arith evaluation in array indexing?


reply via email to

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