Bugzilla – Bug 141394
bash $'foo' quoting bug
Last modified: 2012-04-05 12:00:10 UTC
Older versions of bash used to echo four ones for the following code: echo $(set -- 'a b'; echo $#) echo "$(set -- 'a b'; echo $#)" echo $(set -- $'a b'; echo $#) echo "$(set -- $'a b'; echo $#)" bash-3.1-5 from STABLE as of 4 January 2005 wrongly splits the fourth $'a b' expression into two words, and thus echoes three ones and a two. This seems wrong. (The above is a minimal test case; in the real expression I am using C-escaped characters in the $'' expression.)
Hmmm ... AFAIS from the source code this is a weanted feature. Beside this echo "$(set -- $"a b"; echo $#)" returns 1 instead of 2.
$"text" is a string that is passed through gettext, while $'text' is a string that gets C-style escapes like \t expanded. I cannot imagine that it's intended that $'...' behaves differently in different contexts: $ set -- $'a\tb' $ echo $# "$@" 1 a<tab>b $ echo $(set -- $'a\tb'; echo $# "$@") 1 a b $ echo $(set -- $'a\tb'; echo $# "$@") 2 a b The first two cases are correct, the last one isn't.
Oops, the last case should have been: $ echo "$(set -- $'a\tb'; echo $# "$@")" 2 a b
I thought so :) ... nad have have a single line patch to fix this.
fixed
*** Bug 143272 has been marked as a duplicate of this bug. ***
Created attachment 67684 [details] For reference, this is the fix Werner, did you send this upstream?
done
This is an autogenerated message for OBS integration: This bug (141394) was mentioned in https://build.opensuse.org/request/show/112694 Factory / bash