Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: OPTARG not being set?



Sweth Chandramouli wrote:

> (astaroth)~1: joe='hello world'
> (astaroth)~2: bob=joe
> (astaroth)~3: echo ${joe}
> hello world
> (astaroth)~4: echo ${bob}
> joe
> (astaroth)~5: echo ${${bob}}
> joe
> (astaroth)~6: echo ${(e)bob}
> joe
> (astaroth)~7: echo "echo \${$(echo ${bob})}"
> echo ${joe}
> (astaroth)~8: `echo "echo \${$(echo ${bob})}"`
> joe
> (astaroth)~9: echo ${ZSH_VERSION}
> 3.1.5
> 
> 	i would think that #5 should print hello world,
> that #6 would explicitly cause parameter expansion and
> print hello world, and that #8 would evaluate the results
> of #7, which would be the same as typing #3, and would
> thus print hello world.

For standard 3.1.5 the syntax with an embedded ${...} inside a ${...}
is only useful if the outer ${...} contains some flags or other
modifying stuff. It will then work on the word(s) produced by the
inner${...}.
The (e) flag means the the string resulting from the whole ${...} will 
(at the end) be subject to another expansion (so if you had
bob=\$joe, it would work).
#8 irritates me, especially since:

  % $(echo "echo \${$(echo ${bob})}")

yields ${b}. This almost certainly caused by some weird quoting rules, 
which may even be documented.
Anyway, you should use eval for this:

  % eval echo "\$$bob"

Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author