From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28415 invoked by alias); 14 May 2011 11:51:12 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29281 Received: (qmail 24827 invoked from network); 14 May 2011 11:51:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,FAKE_REPLY_C autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at spf.stack.nl designates 131.155.140.107 as permitted sender) Date: Sat, 14 May 2011 13:41:56 +0200 From: Jilles Tjoelker To: zsh-workers@zsh.org Subject: Re: PATCH: expanding parameters like echo/print builtins Message-ID: <20110514114156.GA12539@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) > [${(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