Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: expanding parameters like echo/print builtins
- X-seq: zsh-workers 29281
- From: Jilles Tjoelker <jilles@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: PATCH: expanding parameters like echo/print builtins
- Date: Sat, 14 May 2011 13:41:56 +0200
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
> [${(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")
result=${result%@}
If trailing newlines are not significant, the syntax is very readable,
like:
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
this.
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