1

I'm having a strange problem with a bash-script. The minimal code to reproduce it is here:

#!/bin/bash

function f() {
    IFS=. read a b <<<"$1"
    echo "a=$a b=$b"
}

f a.b
echo "inside echo: `f a.b`"
cat <<EOT
Inside heredoc: `f a.b`
EOT

The expected output is:

a=a b=b
inside echo: a=a b=b
Inside heredoc: a=a b=b

But I get:

a=a b=b
inside echo: a=a b=b
Inside heredoc: a=a.b b=

What am I missing here?

Update: the bash on my Mac (3.2.48) works as expected. the bash on my debian stable (4.2.37(1)-release) gives the described strangeness.

Niobos
  • 880
  • 4
  • 15

1 Answers1

1

This is a bug in how local environment changes interact with here strings, which has been fixed in the forthcoming version 4.3.

# bash 3.2
% bash tmp.bash
a=a b=b
inside echo: a=a b=b
Inside heredoc: a=a b=b

# bash 4.2
% /usr/local/bin/bash tmp.bash
a=a b=b
inside echo: a=a b=b
Inside heredoc: a=a.b b=

# bash 4.3, release candidate
% bash/bash tmp.bash
a=a b=b
inside echo: a=a b=b
Inside heredoc: a=a b=b
chepner
  • 497,756
  • 71
  • 530
  • 681