Bug 141394 - bash $'foo' quoting bug
Summary: bash $'foo' quoting bug
Status: RESOLVED FIXED
: 143272 (view as bug list)
Alias: None
Product: SUSE Linux 10.1
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: Alpha 4
Hardware: Other Other
: P5 - None : Critical (vote)
Target Milestone: ---
Assignee: Dr. Werner Fink
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-04 14:51 UTC by Andreas Gruenbacher
Modified: 2012-04-05 12:00 UTC (History)
1 user (show)

See Also:
Found By: Other
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
For reference, this is the fix (537 bytes, patch)
2006-02-10 18:17 UTC, Andreas Gruenbacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Gruenbacher 2006-01-04 14:51:31 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.)
Comment 1 Dr. Werner Fink 2006-01-10 11:29:08 UTC
Hmmm ... AFAIS from the source code this is a weanted feature.
Beside this

    echo "$(set -- $"a b"; echo $#)"

returns 1 instead of 2.
Comment 2 Andreas Gruenbacher 2006-01-10 11:59:53 UTC
$"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.
Comment 3 Andreas Gruenbacher 2006-01-10 12:01:52 UTC
Oops, the last case should have been:

$ echo "$(set -- $'a\tb'; echo $# "$@")"
2 a b
Comment 4 Dr. Werner Fink 2006-01-10 12:04:45 UTC
I thought so :) ... nad have have a single line patch to fix this.
Comment 5 Dr. Werner Fink 2006-01-10 12:51:11 UTC
fixed
Comment 6 Dr. Werner Fink 2006-01-16 13:46:19 UTC
*** Bug 143272 has been marked as a duplicate of this bug. ***
Comment 7 Andreas Gruenbacher 2006-02-10 18:17:23 UTC
Created attachment 67684 [details]
For reference, this is the fix

Werner, did you send this upstream?
Comment 8 Dr. Werner Fink 2006-02-13 11:39:41 UTC
done
Comment 9 Bernhard Wiedemann 2012-04-05 12:00:10 UTC
This is an autogenerated message for OBS integration:
This bug (141394) was mentioned in
https://build.opensuse.org/request/show/112694 Factory / bash