bug-bash
[Top][All Lists]
Advanced

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

Re: expansions upon arithmetic evaluation in array subscripts


From: Chet Ramey
Subject: Re: expansions upon arithmetic evaluation in array subscripts
Date: Tue, 14 Oct 2014 20:51:32 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 10/14/14, 2:17 PM, Linda Walsh wrote:
> 
> 
> Chet Ramey wrote:
> 
>>
>>> Note that it's not only variable expansion, it's also tilde
>>> (even though ~ is also an arithmetic operator) expansion.
>>>
>>> $ HOME=1 a='b[~]'  bash -c 'b=(1 2 3); echo $((a))'
>>> 2
>>>
>>> That means for instance that
>>> foo=-1
>>> echo $((a[~foo]))
>>>
>>> won't work on systems where there's a "foo" user.
>>
>> OK.
> ---
> 
> Question (or maybe suggestion?):
> is it possible, when looking at the contents of what is in
> '[]', to indicate whether or not text is acceptable, or
> whether it would be limited to numbers only?

That's not quite the question.  The question is which word expansions
to perform on the string between the brackets before passing it to the
expression evaluator. ksh93 and bash agree that tilde expansion is one
of those; other shells, like mksh and zsh, disagree.  All shells agree
that tilde expansion is not one of the expansions performed by $((...)),
another place where the results of the expansion are passed to the
arithmetic evaluator, since Posix specifies it.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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