bug-bash
[Top][All Lists]
Advanced

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

Re: declare a="$b" if $a previously set as array


From: Chet Ramey
Subject: Re: declare a="$b" if $a previously set as array
Date: Sun, 14 Dec 2014 14:45:06 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 12/7/14 11:16 PM, Eduardo A. Bustamante López wrote:
> On Sun, Dec 07, 2014 at 07:34:53PM -0800, Linda Walsh wrote:
>> Only if you properly quote "external input".
> Well, that's the whole point, as a script writer, I don't expect to get
> arbitrary code execution here:
> 
> | address@hidden:~/t$ unset var; value='[$(ls -l)]=1 [2]=2'; declare -a 
> var="($value)"; declare -p var
> | bash: total 0: syntax error in expression (error token is "0")

Yeah, that's what we're discussing.

> Or here:
> | address@hidden:~/t$ a=(1 2 3); k='a[$(ls -l)]'; echo "${a[k]}"
> | bash: total 0: syntax error in expression (error token is "0")
> 
> And I *shouldn't* have to worry about that.

But the ship has sailed on this one.  Every shell that implements indexed
arrays does what bash does here.

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



reply via email to

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