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

PATCH: more substitution documentation



This is more less my explanation of Andrej's other query yesterday, which I
think I now understand.  If anyone wants to suggest rearranging the
information in this part of the manual, please go ahead and say where you
want it to appear.

--- Doc/Zsh/expn.yo.js	Wed Mar 17 11:51:19 1999
+++ Doc/Zsh/expn.yo	Thu Mar 18 10:11:47 1999
@@ -729,6 +729,21 @@
 )
 enditem()
 
+Any joining and splitting of words which is necessary occurs in that order,
+and after any other substitutions performed on the value at that level of
+substitution; this includes implicit splitting on the characters in
+tt($IFS) when the option tt(SH_WORD_SPLIT) is set.  In particular, when
+splitting is requested on an array value it is first joined, either using
+any string given by the tt(LPAR()j)tt(RPAR()) flag, or a space if there is
+none.  So if tt($foo) contains the array tt(LPAR()ax1 bx1)tt(RPAR()), then
+tt(${(s/x/)foo}) produces the words `tt(a)', `tt(1 b)' and `tt(1)', while
+tt(${(j/x/s/x/)foo}) produces `tt(a)', `tt(1)', `tt(b)' and `tt(1)'.  As
+substituion occurs before either joining or splitting, the operation
+tt(${(s/x/)foo%%1*}) first generates the modified array tt(LPAR()ax
+bx)tt(RPAR()), which is joined to give tt("ax bx"), and then split to give
+`tt(a)', `tt( b)' and `'.  The final empty string will then be elided, as
+it is not in double quotes.
+
 texinode(Command Substitution)(Arithmetic Expansion)(Parameter Expansion)(Expansion)
 sect(Command Substitution)
 cindex(command substitution)

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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