On 07/25/2011 03:45 PM, Linda Walsh wrote:
I mistyped that but it brings me to an interesting
conundrum:

GLOBAL="hi there"
{foo=GLOBAL echo ${!foo}; }

This says:

evaluate ${!foo}, and pass that expansion to 'echo', with foo=GLOBAL in the environment of echo. You are invoking behavior that POSIX leaves undefined (that is, bash is perfectly fine evaluating ${!foo} prior to assigning foo, but bash would also be okay if it assigned foo prior to evaluating ${!foo}. Hence, you got no output.

But:
{ foo=GLOBAL;echo ${!foo}; }
> hi there

The extra ; forces the semantics. Here, the assignment to foo is a different statement than the expansion of of ${!foo}. And while ${!foo} is a bash extension, it still proves that this is a case where foo was assigned prior to its use.

Weird...

Not if you think about it properly.

--
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Reply via email to