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: Greg Wooledge
Subject: Re: Array not defined when being set inline
Date: Tue, 10 Oct 2017 08:21:48 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Oct 10, 2017 at 08:00:58AM -0400, shawn wilson wrote:
> I guess that's the right way to describe what I'm seeing:
> 
> [swilson@localhost ~]$ unset f; f=(aaa bbb ccc) declare -p f
> declare -x f="(aaa bbb ccc)"

You placed a string variable in the temporary execution environment of
the declare command.  If you wanted an actual array variable that would
persist past this command, you need a semicolon or newline after the
assignment, and before the declare command.

What you did:

wooledg:~$ unset f; f=(aaa bbb ccc) declare -p f
declare -x f="(aaa bbb ccc)"
wooledg:~$ declare -p f
bash: declare: f: not found

What you probably wanted:

wooledg:~$ unset f; f=(aaa bbb ccc); declare -p f
declare -a f=([0]="aaa" [1]="bbb" [2]="ccc")
wooledg:~$ declare -p f
declare -a f=([0]="aaa" [1]="bbb" [2]="ccc")

See also: http://mywiki.wooledge.org/BashFAQ/104



reply via email to

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