From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18478 invoked by alias); 26 May 2010 19:54:55 -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: 27976 Received: (qmail 10124 invoked from network); 26 May 2010 19:54:52 -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.9 required=5.0 tests=BAYES_00,MISSING_HEADERS, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.47 as permitted sender) Date: Wed, 26 May 2010 20:54:17 +0100 From: Peter Stephenson Cc: Zsh hackers' list Subject: Re: ${(q)...} for newline Message-ID: <20100526205417.6a3dd12a@pws-pc> In-Reply-To: <20100525154824.49616502@csr.com> References: <10739.1274644720@pws-pc> <201005232045.o4NKjdLO027329@pws-pc.ntlworld.com> <20100525154824.49616502@csr.com> X-Mailer: Claws Mail 3.7.5 (GTK+ 2.18.9; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.1 cv=1ggfb5FlKZQUfF3vzm9UBYZ2uTfLsbs/8dSljwg5+mE= c=1 sm=0 a=wbKXeunVgZ0A:10 a=DogomfpGjd0A:10 a=kj9zAlcOel0A:10 a=4UtWO5riAAAA:8 a=NLZqzBF-AAAA:8 a=UH_HHMgNdjPowZVplzIA:9 a=e2B0ktiNZMyAuGFWmicA:7 a=F27hfsvKkMrhNT1gUT36rGMYCNkA:4 a=CjuIK1q_8ugA:10 a=Shd8Sdw-9eQA:10 a=_dQi-Dcv4p4A:10 a=d5zQhkAkIXawReBx:21 a=KgcgkJyI9xdaKr--:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Tue, 25 May 2010 15:48:24 +0100 Peter Stephenson wrote: > However, we don't actually say in the (already long) manual entry giving > the rules for variable expansion at what part either quoting or empty > element removal takes place. The latter appears to be the last thing of all, > i.e. at the point where we decide to insert this into the list of arguments > (or otherwise). I should probably concoct something. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.113 diff -p -u -r1.113 expn.yo --- Doc/Zsh/expn.yo 12 May 2010 10:07:01 -0000 1.113 +++ Doc/Zsh/expn.yo 26 May 2010 19:51:21 -0000 @@ -1172,7 +1172,15 @@ Any modifiers, as specified by a trailin noderef(Modifiers) in noderef(History Expansion)), are applied to the words of the value at this level. ) -item(tt(8.) em(Forced Joining))( +item(tt(8.) em(Character evaluation))( +Any tt((#)) flag is applied, evaluating the result so far numerically +as a character. +) +item(tt(9.) em(Length))( +Any initial tt(#) modifier, i.e. in the form tt(${#)var(var)tt(}), is +used to evaluate the length of the expression so far. +) +item(tt(10.) em(Forced Joining))( If the `tt((j))' flag is present, or no `tt((j))' flag is present but the string is to be split as given by rules tt(8.) or tt(9.), and joining did not take place at step tt(4.), any words in the value are joined @@ -1180,36 +1188,51 @@ together using the given string or the f Note that the `tt((F))' flag implicitly supplies a string for joining in this manner. ) -item(tt(9.) em(Forced Splitting))( +item(tt(11.) em(Case modification))( +Any case modification from one of the flags tt((L)), tt((U)) or tt((C)) +is applied. +) +item(tt(12.) em(Prompt evaluation))( +Any prompt-style formatting from the tt((%)) family of flags is applied. +) +item(tt(13.) em(Quote application))( +Any quoting or unquoting using tt((q)) and tt((Q)) and related flags +is applied. +) +item(tt(14.) em(Visibility enhancment))( +Any modifications to make characters visible using the tt((V)) flag +are applied. +) +item(tt(15.) em(Forced Splitting))( If one of the `tt((s))', `tt((f))' or `tt((z))' flags are present, or the `tt(=)' specifier was present (e.g. tt(${=)var(var)tt(})), the word is split on occurrences of the specified string, or (for tt(=) with neither of the two flags present) any of the characters in tt($IFS). ) -item(tt(10.) em(Shell Word Splitting))( +item(tt(16.) em(Shell Word Splitting))( If no `tt((s))', `tt((f))' or `tt(=)' was given, but the word is not quoted and the option tt(SH_WORD_SPLIT) is set, the word is split on occurrences of any of the characters in tt($IFS). Note this step, too, takes place at all levels of a nested substitution. ) -item(tt(11.) em(Uniqueness))( +item(tt(17.) em(Uniqueness))( If the result is an array and the `tt((u))' flag was present, duplicate elements are removed from the array. ) -item(tt(12.) em(Ordering))( +item(tt(18.) em(Ordering))( If the result is still an array and one of the `tt((o))' or `tt((O))' flags was present, the array is reordered. ) -item(tt(13.) em(Re-Evaluation))( +item(tt(19.) em(Re-Evaluation))( Any `tt((e))' flag is applied to the value, forcing it to be re-examined for new parameter substitutions, but also for command and arithmetic substitutions. ) -item(tt(14.) em(Padding))( +item(tt(20.) em(Padding))( Any padding of the value by the `tt(LPAR()l.)var(fill)tt(.RPAR())' or `tt(LPAR()r.)var(fill)tt(.RPAR())' flags is applied. ) -item(tt(15.) em(Semantic Joining))( +item(tt(21.) em(Semantic Joining))( In contexts where expansion semantics requires a single word to result, all words are rejoined with the first character of tt(IFS) between. So in `tt(${LPAR()P)tt(RPAR()${LPAR()f)tt(RPAR()lines}})' @@ -1218,6 +1241,15 @@ joined again before the tt(P) flag can b If a single word is not required, this rule is skipped. ) +item(tt(22.) em(Empty argument removal))( +If the substitution does not appear in double quotes, any resulting +zero-length argument, whether from a scalar or an element of an array, +is elided from the list of arguments inserted into the command line. + +Strictly speaking, the removal happens later as the same happens with +other forms of substitution; the point to note here is simply that +it occurs after any of the above parameter operations. +) enditem() subsect(Examples) -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/