Here's another corner-case bug with assigning $* to a variable (i.e.:
foo=$*). If IFS is empty, the $* expansion removes any $'\001' (^A) and
$'\177' (DEL) characters. If IFS contains a value, each ^A and DEL
character is prefixed by another $'\001'. If IFS is unset, the bug does
not show up at all.

This is another case where quoting the $* (i.e.: foo="$*") works around
the bug, yet it's still a bug.

Test script:

fn() {
    foo=$*
    printf '%s' "$foo" | od -c | awk 'NR==1 { $1=""; print; }'
}
teststring=$(printf '\001\002\003\177')
for IFS in '' ' ' 'X' ' X'; do
    fn "$teststring"
done
unset -v IFS
fn "$teststring"

Expected output (and actual output from every non-bash shell):

 001 002 003 177
 001 002 003 177
 001 002 003 177
 001 002 003 177
 001 002 003 177

Actual output (bash 4.4.12, bash-20171110 snapshot):

 002 003
 001 001 002 003 001 177
 001 001 002 003 001 177
 001 001 002 003 001 177
 001 002 003 177

Actual output (bash 4.3.39, 4.2.53, 4.1.17, 3.2.57):

 001 002 003 177
 002 003
 001 002 003 177
 001 002 003 177
 001 002 003 177

Actual output (bash 2.05b):

 001 002 003
 001 002 003
 001 002 003
 001 002 003
 001 002 003

- Martijn

Reply via email to