Discussion:
Another ^A bug
Martijn Dekker
2018-11-20 17:24:04 UTC
Permalink
That ^A / $'\1' character just keeps causing trouble...

This is a bug with IFS. Including a $'\1' character anywhere in IFS
causes expansions in shell assignments to discard that character.

$ bash -c "c=$'Y\1Y';
for IFS in $'\1' $'\2' $'x\1' $'x\2' $'\1x' $'\2x'; do
v=X\${c}X;
printf %s \"\$v\" | od -a | awk 'NR==1 { \$1=\"\"; print }';
done"

Output on bash 4.4 and current git:
X Y Y X
X Y soh Y X
X Y Y X
X Y soh Y X
X Y Y X
X Y soh Y X

Expected output, on bash 4.3 and earlier, and all other shells:
X Y soh Y X
X Y soh Y X
X Y soh Y X
X Y soh Y X
X Y soh Y X
X Y soh Y X

Note that quoting the assigned value is an effective workaround. But in
shell grammar, IFS should never have any influence on true shell
assignments (as opposed to assignment-arguments) and quoting expansions
should not be necessary. (This paragraph is included to pre-empt readers
who would reply "just quote everything". Yes, I know. It's still a bug.)

Thanks,

- Martijn
Chet Ramey
2018-11-29 23:31:10 UTC
Permalink
Post by Martijn Dekker
That ^A / $'\1' character just keeps causing trouble...
This is a bug with IFS. Including a $'\1' character anywhere in IFS causes
expansions in shell assignments to discard that character.
$ bash -c "c=$'Y\1Y';
    for IFS in $'\1' $'\2' $'x\1' $'x\2' $'\1x' $'\2x'; do
        v=X\${c}X;
        printf %s \"\$v\" | od -a | awk 'NR==1 { \$1=\"\"; print }';
    done"
Thanks for the report. Cases like this never come up in the real world,
so edge cases like this slip by.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://tiswww.cwru.edu/~chet/
Loading...