bug-bash
[Top][All Lists]
Advanced

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

Re: Code Execution in Mathematical Context


From: Chet Ramey
Subject: Re: Code Execution in Mathematical Context
Date: Thu, 6 Jun 2019 10:18:30 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

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    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

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