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

Re: nohistsubstpattern and :s//



On Jul 6,  9:49am, Peter Stephenson wrote:
}
} I don't think it's *that* much of a problem that the modifiers behave
} differently in contexts that are themselves intrinsically rather
} different.

Some doc below, but there's still some odd stuff going on.

$b != ${b} in parameter expansion:

torch% a=(abc dbe fbg)
torch% unset b
torch% print ${a:gs/b/$b/}  
a d f
torch% print ${a:gs/b/${b}} 
ac de fg
torch% b=/
torch% print ${a:gs/b/$b/}     
a d f
torch% print ${a:gs/b/${b}}
a/c d/e f/g

(I have no idea why the strings are being truncated in the $b case no
matter what the value of $b.)

No way to quote "/" when using in a glob qualifier:

torch% ls *a*
config.modules.local  config.status  Makefile  stamp-h
torch% b=/
torch% print *a*(:s/a/$b/)
config.modules.locl config.sttus Mkefile stmp-h
torch% b=X
torch% print *a*(:s/a/$b/)
config.modules.locXl config.stXtus MXkefile stXmp-h

(Perhaps ${(b)...} should put backslashes in front of slashes? But two
backslashes are needed:

torch% print *a*(:s/a/\//)
config.modules.locl config.sttus Mkefile stmp-h
torch% print *a*(:s/a/\\//)
config.modules.loc/l config.st/tus M/kefile st/mp-h

so maybe this just calls for using a different delimiter.)


diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 7d4e6fc..1e1fc52 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -319,6 +319,19 @@ forms of expansion.
 Note that if a `tt(&)' is used within glob qualifiers an extra backslash
 is needed as a tt(&) is a special character in this case.
 
+Also note that the order of expansions affects the interpretation of
+var(l) and var(r).  When used in a history expansion, which occurs before
+any other expansions, var(l) and var(r) are treated as literal strings
+(except as explained for tt(HIST_SUBST_PATTERN) below).  When used in
+parameter expansion, the replacement of var(r) into the parameter's value
+is done first, and then any additional process, parameter, command,
+arithmetic, or brace references are applied, which may evaluate those
+substitutions and expansions more than once if var(l) appears more than
+once in the starting value.  When used in a glob qualifier, any
+substitutions or expansions are performed once at the time the qualifier
+is parsed, even before the `tt(:s)' expression itself is divided into
+var(l) and var(r) sides.
+
 If the option tt(HIST_SUBST_PATTERN) is set, var(l) is treated as
 a pattern of the usual form described in
 ifzman(the section FILENAME GENERATION below)\



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