[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
foo=$*: ^A and DEL are prefixed or removed
From: |
Martijn Dekker |
Subject: |
foo=$*: ^A and DEL are prefixed or removed |
Date: |
Fri, 24 Nov 2017 09:17:42 +0100 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 |
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- foo=$*: ^A and DEL are prefixed or removed,
Martijn Dekker <=