[pacman-dev] [PATCH] makepkg: fix variable backup/restore for splitpkg

Aaron Griffin aaronmgriffin at gmail.com
Tue Jun 9 11:48:15 EDT 2009


On Mon, Jun 8, 2009 at 11:19 PM, Allan McRae<allan at archlinux.org> wrote:
>> -               eval "${indirect}=\"${!var}\""
>> +               eval "${indirect}=(\${$var[@]})"
>>
>
> Bonus points for anyone who understands what I was doing and what is being
> done now...  All I know is that is works!  :)

Well... what it was doing previously, I don't know. I can't seem to
find docs on what ! does in this context.

But what it's doing now is easy to understand. The non-confusing parts
of the string:
   eval "something=( .......... )"
Well, that's understandable... let's go in one step:
   \${....[@]}
OK, that makes sense too... one more step:
   $var

Ok, so $var is expanded (say, to 'foo'), and then we snag the contents
of foo (${foo[@]}), and then put all that back in some new array, for
safekeeping.

Re: the ${!foo} syntax: http://tldp.org/LDP/abs/html/bashver2.html#VARREFNEW

It's shorthand for this:

foo="bar"
bar=5

now I want the value specified by the string in $foo

previously, you would do:
eval "myvar=\$$foo", which equates to "myval=\$bar" and then "myval=5"

The ! syntax makes this less confusing. myval=${!foo} does the exact same thing


More information about the pacman-dev mailing list