Dennis Williamson
2016-12-31 04:10:50 UTC
On Dec 30, 2016 11:04 PM, "PePa" <***@passchier.net> wrote:
It seems that when piping into bash, variables have different
'retention' than functions:
r=23; echo $r; echo -e "r=bc\necho $r" |bash
23
23
r(){ echo Hey;}; r; echo -e "r(){ echo Ho;}\nr" |bash
Hey
Ho
Is this a bug, or is there a rationale?
Thanks,
Peter
It's because you have the echo argument inside double quotes and the
variable is expanded before the echo or the piped bash are executed. Change
to single quotes and the expansion will be delayed.
It seems that when piping into bash, variables have different
'retention' than functions:
r=23; echo $r; echo -e "r=bc\necho $r" |bash
23
23
r(){ echo Hey;}; r; echo -e "r(){ echo Ho;}\nr" |bash
Hey
Ho
Is this a bug, or is there a rationale?
Thanks,
Peter
It's because you have the echo argument inside double quotes and the
variable is expanded before the echo or the piped bash are executed. Change
to single quotes and the expansion will be delayed.