On 6/6/19 8:53 AM, Greg Wooledge wrote:
> On Thu, Jun 06, 2019 at 11:33:56AM +1000, David wrote:
>> Regarding $((...)) when Chet refers above to "the expression between the 
>> parens"
>> he means whatever is between the parentheses, in this case the three dots.
>>
>> If I understand correctly, Chet is saying there that $((...)) is
>> parsed as if it was written
>> $(("...")) and therefore any single quotes inside the parentheses are
>> not special.
> 
> But...
> 
> On Tue, Jun 04, 2019 at 09:24:27AM -0400, Greg Wooledge wrote:
>> wooledg:~$ a=(foo bar baz)
>> wooledg:~$ i='$(date >&2)'
>> wooledg:~$ echo $(( a[$i] ))
>> Tue 04 Jun 2019 09:23:28 AM EDT
>> 0
> 
>> wooledg:~$ echo $(( 'a[$i]' ))
>> bash: 'a[$(date >&2)]' : syntax error: operand expected (error token is 
>> "'a[$(date >&2)]' ")
> 
> I definitely got different results when I added single quotes.

These two things are consistent. If you treat the expression as if it
were within double quotes for expansion, the single quotes are preserved
(they're not special in double quotes and aren't removed by quote
removal) and the arithmetic evaluator doesn't know what to do with them.


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

Reply via email to