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

Re: aliases not getting expanded inside functions?



Carlos Carvalho wrote:
>The manual says "Recognize the same escape sequences as the print
>builtin in string arguments to subsequent flags." So there should be a
>relation.

That's the "p" (*small* p) flag.  Phil was demonstrating the "P"
(*capital* P) parameter expansion flag, which zshexpn(1) describes thus:

#        P      This  forces  the value of the parameter name to be
#               interpreted as  a  further  parameter  name,  whose
#               value  will be used where appropriate. If used with
#               a nested parameter  or  command  substitution,  the
#               result of that will be taken as a parameter name in
#               the same way.  For example, if you  have  `foo=bar'
#               and `bar=baz', the strings ${(P)foo}, ${(P)${foo}},
#               and ${(P)$(echo bar)} will be expanded to `baz'.

To use this kind of parameter alias for setting, you can do

% foo=bar bar=baz
% echo ${(P)foo}
baz
% : ${(P)foo::=xxx}
% echo ${(P)foo}
xxx
% echo $foo $bar
bar xxx

which also works where foo is an array reference such as "array[3]".

-zefram



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