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

Re: [PATCH] Enable further expansion of parameter name by ${!...}



On Jan 25, 11:38pm, ZyX wrote:
} Subject: Re: [PATCH] Enable further expansion of parameter name by ${!...}
}
} 25.01.2015, 23:25, "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>:
} >
} > Don't we already have something like this for ksh emulation?  Except that
} > it acts like (k) instead of like (P)?  Although I can't find this in the
} > documentation anywhere, right at the moment.
} 
} I have ksh installed and here `${!VAR}` outputs `VAR` regardless of
} whether $VAR is defined and what type and what value does it have.

I thought I recalled something about that.  So it would appear that
whatever interpretation we're giving it already in ksh mode, is wrong.

} [Manual page][1] says that it should actually expand to "the name of
} the variable referred to by vname" and says that this will be `VAR`
} unless it is a name reference (I have only tried strings, arrays and
} associative arrays).
}
} [1]: http://unixhelp.ed.ac.uk/CGI/man-cgi?ksh+1

So it would appear that ${!var} in bash is ${(P)var} (just tried it, it
does so) where as ${!var} in ksh inhibits the expansion of a nameref
to its value and instead just prints the name to which the nameref
refers, which in zsh is [usually] just ${var}.

Interesting thing I didn't know about namerefs -- if you do

nameref foo=bar
nameref bar=baz

then the nameref for $foo is broken (${!foo} prints ".deleted"), but
if you do it the other way round

nameref bar=baz
nameref foo=bar

then ${!foo} prints "baz" and ${foo} gives the value of ${baz}.

-- 
Barton E. Schaefer



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