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

Reply via email to