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

Re: nohistsubstpattern and :s//



On Jul 7,  4:28pm, Peter Stephenson wrote:
}
} Even this afternoon(!) I'm still getting
} 
} % a=(abc dbe fbg)
} % setopt histsubstpattern
} % unset b
} % print ${a:gs/b/$b/}
} ac de fg
} 
} and I confirmed with zsh -f, too.

Ah!

torch% a=(abc dbe fbg)
torch% setopt histsubstpattern
torch% print ${a:gs/b/$b/}
ac de fg
torch% setopt nohistsubstpattern
torch% print ${a:gs/b/$b/}
a d f

So with histsubstpattern set it looks like $b is expanded before the
substitution takes place, but with nohistsubstpattern (the default,
which is why I never showed the option change in any of my previous
examples) the expansion happens after the substitution.

Demonstrable with a scalar substitution instead of an array:

torch% a=(abc dbe fbg) 
torch% b=1         
torch% print ${a:s/b/$[b++]/}
a1c d2e f3g
torch% setopt histsubstpattern
torch% print ${a:s/b/$[b++]/} 
a4c d5e f6g
torch% a="$a"				<-- scalar + histsubstpattern
torch% print ${a:gs/b/$[b++]/} 
a7c d7e f7g				<-- only one increment of b
torch% unsetopt histsubstpattern
torch% print ${a:gs/b/$[b++]/}  
a8c d9e f10g				<-- three increments of b

No memory errors found by valgrind in either case.



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