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

Re: is variable with variable name possible?



2011-04-05 00:32:27 +0200, Mikael Magnusson:
[...]
> > eval "$somevar=\$PWD"
> >
> > is more legible and more portable.
> 
> But your quotes do nothing (assuming $somevar has a sane value), did you mean
> eval $somevar=\"\$PWD\"
> or possibly more readable version
> eval $somevar='"$PWD"'

Those double quotes are not necessary.

> ? AFAICT, it works without any quotes with globsubst and shwordsplit
> set too though, as long as you quote the $ in $PWD, tried in both zsh
> and bash.
[...]

If you don't quote $somevar, you ask the shell to split it which
it will do according to the current value of IFS (assuming
shwordsplit).

If you quote it, you don't have to worry what the value of $IFS
is.

-- 
Stephane



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