Dash remove prefix expansion (${a#b}) doesn't work in double quotes
Bug #239561 reported by
Daniel Benamy
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dash (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: dash
Kubuntu 8.04
dash 0.5.4-8ubuntu1
In bash:
$ foo="abcde"
$ echo ${foo#'ab'}
cde
$ echo "${foo#'ab'}"
cde
In dash:
$ foo="abcde"
$ echo ${foo#'ab'}
cde
$ echo "${foo#'ab'}"
abcde
I think I understand how this should work, but I could be confused. http://
Thanks!
Dan
To post a comment you must log in.
This has been discussed at the Austin Group (POSIX fixing/development) recently, but no definitive interpretation has been issued yet. The current standard is rather vague to allow various implementations to comply.
I agree that bash's behaviour is better here, but it is possible that the interpretation will be such that dash's behaviour is also compliant.
In other cases such as echo "${foo+'ab}", I think bash interpreted the current standard incorrectly (it requires matching quotes, but if you give "${foo+'ab'}" it does not remove them), while dash has more sensible behaviour. In both cases, ksh93 (the real Korn shell from AT&T, probably packaged as "ksh") behaves sensibly, by distinguishing between +-=? and #% expansions.
Workarounds for this are to put the expansion in a lone assignment (so it does not need double-quotes around it) or otherwise add indirection through variables (e.g. q=\' then use $q instead of a single-quote).