bug-bash
[Top][All Lists]
Advanced

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

Re: Array not defined when being set inline


From: Dan Douglas
Subject: Re: Array not defined when being set inline
Date: Tue, 10 Oct 2017 08:06:55 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

On 10/10/2017 07:00 AM, shawn wilson wrote:
> I guess that's the right way to describe what I'm seeing:
> 
> address@hidden ~]$ unset f; f=(aaa bbb ccc) declare -p f
> declare -x f="(aaa bbb ccc)"
> address@hidden ~]$ unset f; f=("aaa" "bbb" "ccc") declare -p f
> declare -x f="(aaa bbb ccc)"
> address@hidden ~]$ unset f; f=(aaa bbb ccc)
> address@hidden ~]$ declare -p f
> declare -a f='([0]="aaa" [1]="bbb" [2]="ccc")'
> 
> Is this known? What exactly is going on / what does this mean?
> 

Bash parses the array assignment as though it were valid while reading
words, assignments, and redirects of the command. After processing
expansions, the saved assignment text is re-interpreted as a string
assignment, presumably because at this point bash no longer cares about
the quoting of metacharacters so they're just treated as literal.

Array assignments aren't valid preceding commands of course because
the environment fundamentally stores strings / key-value pairs of
binary blobs.

This should probably be an error, but this is what bash has always done,
and this hasn't really caused any problems other than occasionally
tricking people into thinking arrays are somehow exportable.

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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