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: Linda Walsh
Subject: Re: expansions upon arithmetic evaluation in array subscripts
Date: Tue, 14 Oct 2014 11:17:33 -0700
User-agent: Thunderbird



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?

i.e. if 'a' is not a 'hash', then the contents of []
should only ever be treated as a number.  With the exception
of an 'odd' case where "user foo" has a home directory composed
only of numeric digits, wouldn't it make sense to only use
numeric expansions in side of array brackets -- with word
expansions like home-dirs only attempted inside of hash-bracket
expansions?

It seems that would mostly address expansions inside brackets
(assuming that controlling expansion could be done with-respect-to
context.




reply via email to

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