bash 4.4 not passing variables to sub-shell

Viewed 1424

Bash 4.4 and 4.3 seem to behave differently with regards to passing variables into subshells or heredocs.

From @CharlesDuffy a simple reproduction:

export var=0; var=1 cat <<<"$(env | grep '^var')"

Bash 4.4 outputs var=0, bash 4.3 outputs var=1.

My original script for reproducing the problem:

TZ=Europe/London
timezone=Asia/Tokyo
echo TZ=$TZ
echo timezone=$timezone

date +%H:%M
TZ=$timezone date +%H:%M

IFS=':' TZ=$timezone read hour minute <<EOF
        $(date +%H:%M)
EOF
echo TZOUTER $hour-$minute

IFS=':' read hour minute <<EOF
        $(TZ=$timezone date +%H:%M)
EOF
echo TZINNER $hour-$minute

Bash 4.3 (Ubuntu 16.04) gives:

TZ=Europe/London
timezone=Asia/Tokyo
14:52
22:52
TZOUTER 22-52
TZINNER 22-52

Bash 4.4 (Ubuntu 17.04) gives:

TZ=Europe/London
timezone=Asia/Tokyo
13:53
22:53
TZOUTER 13-53
TZINNER 22-53

(On bash 4.3 both the inner and outer approaches give the same time, on bash 4.4 the TZOUTER gives the original TZ value).

Does anyone know why this changed? I've looked over https://lists.gnu.org/archive/html/info-gnu/2016-09/msg00008.html but I can't work out which change caused the alteration to behavior.

3 Answers
Related