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

Parameter assignment in a redirection word



Hi,

Please help me to clarify this situation:

	$ (echo foo) > ${myvar:=tmpfile}
	$ echo ${myvar:-still unset}
	still unset

Why $myvar is set in a subshell instead of a parent process in this
case?  I was unable to find where it's documented, but I've checked
some other shells, and of course it turned out that zsh is not alone
here, at least bash is doing the same.  OTOH, FreeBSD sh, oksh and
dash all seem to set the variable in a parent.  I was thinking that
the latter is the only expected behavior, just like in

	$ echo foo > ${myvar:=tmpfile}
	$ echo ${myvar:-still unset}
	tmpfile

which, by the way, works identically in all the shells that I've
tested.  But after I tried

	$ (echo foo) | tee ${myvar:=tmpfile}

and found that $myvar is set by a parent in zsh only, I'm not sure
what to expect any longer.  Could anyone shed some light on what's
going on here?




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