bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Command or process substitution resets alias name tracking during alias


From: Dan Douglas
Subject: Command or process substitution resets alias name tracking during alias expansion?
Date: Tue, 22 Nov 2016 16:46:19 -0600

Hi. Here's a change between bash 4.1 and 4.2 that persists in 4.4.
(Added the counter to make it stop).

address@hidden $ ( bash-4.2 ) <<\EOF
shopt -s expand_aliases; n=0
alias @='((n >= 5)) && alias @="unalias @; echo"
printf "$((n++)) " $()
@'
@
EOF

0 1 2 3 4 5

address@hidden $ ( bash-4.1 ) <<\EOF
shopt -s expand_aliases; n=0
alias @='((n >= 5)) && alias @="unalias @; echo"
printf "$((n++)) " $()
@'
@
EOF

The empty command expansion triggers this. I don't think it's an alias
quirk I've known about though. (Too bad because it's faster than eval
and I don't know of another way to make this happen).

If an alias that's read lexically outside of any other command in the
"global context" generates two "complete commands" on separate lines,
why is the second command considered within the scope of the current
alias expansion even though it technically hasn't been "read" yet?
Isn't it extra work for bash to remember exactly what code was
generated by which aliases just to keep track of which words to
ignore? I would think the first command would be evaluated before the
second command is read even if it's the product of an alias.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]