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

Re: PATCH: expanding parameters like echo/print builtins

> [${(g)parameter} expansion for expanding like echo/print]

Am I really strange in thinking this should really be done using command
substitution of echo, print or printf with appropriate options?

Admittedly, this requires precautions if trailing newlines are
significant, like (for expanding similar to the System V echo):

result=$(printf '%b@' "$v")

If trailing newlines are not significant, the syntax is very readable,

result=$(printf '%b' "$v")

result=$(printf "$v") # careful with %

result=$(print - "$v")

Command substitution can be slow because it forks a subshell, but ksh93
and FreeBSD sh prove it need not be -- a subshell can be emulated
without a fork in many cases and POSIX is explicitly worded to allow

Other tricks are using eval with $'...' (requires special care for ' and
is not in POSIX.1-2008).

In general, I think the ${(foo)parameter} forms are mostly write-only
code for interactive use, except perhaps if you use them a lot.

Jilles Tjoelker

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