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

Re: Variable with Variable Name



On Wed, Sep 12, 2007 at 01:43:46PM +0000, zzapper wrote:
> Hi,
> 
> function SSS()
> {
> # description : create a set variable with variable name
> $1=`pwd`;  # What I want but THIS DOESNT WORK
> echo $1
> }
> 
> So if I called this
> 
> > SSS fred
> 
> Would create a variable fred containing the path of the current directory
[...]

SSS() {
  eval "$1=\$PWD"
  eval "printf '%s\n' \"$1=\$$1\""
}

Which happens to even be POSIX code.

-- 
Stéphane



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