help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] indirection for arrays


From: Greg Wooledge
Subject: Re: [Help-bash] indirection for arrays
Date: Wed, 9 May 2012 08:26:22 -0400
User-agent: Mutt/1.4.2.3i

On Wed, May 09, 2012 at 02:42:34AM -0500, Dan Douglas wrote:
>  ~ $ x=y; y=(1 2 3); declare -a "$x"+=(a b c); declare -p y
> -bash: syntax error near unexpected token `('

I'm not sure what this was trying to demonstrate.  That the syntax does
not work?

> And it isn't limited to declare - eval does it too:

(Does what?)

>  $ eval x=(1 2 3); declare -p x
> declare -a x='([0]="1" [1]="2" [2]="3")'

Yes, "eval" is the only way to pass arrays to a function by name in
bash.  And eval is a bitch.  It can be used safely, but only if you are
*extremely* careful, and agonize over every single byte of the code as
if your life depends on it.  (And even then you still might have to do
some printf %q work in advance.)

Working with eval reminds of me integral calculus.  You're trying to
come up with a piece of code which, after it's been eval'ed, gives
you the command that you actually want.  Coming up with that code is a
nondeterministic process.



reply via email to

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