dash gives "Syntax error: Bad substitution" on valid syntax
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
dash (Debian) |
Fix Released
|
Unknown
|
|||
dash (Ubuntu) |
Fix Released
|
Medium
|
Micah Cowan |
Bug Description
Binary package hint: dash
This operation fails on Ubuntu:
$ /bin/sh -c 'if false; then d="${foo/bar}"; fi'
/bin/sh: Syntax error: Bad substitution
When used with other POSIX shells it succeeds. While semantically the variable reference ${foo/bar} is not valid, this is not a syntax error according to POSIX, and since the variable assignment expression is never invoked (because it's within an "if false") it should not be seen as an error.
I ran into this because after restarting my system I could no longer log in. It turns out that the problem was (a) I had edited .gnomerc to source my .bashrc file so that my environment would be set properly, and (b) I had added some new code to my .bashrc WITHIN A CHECK FOR BASH! that used bash's ${var/match/sub} feature. Even though this code was within a "case $BASH_VERSION; in *[0-9]*) ... esac (so dash would never execute it since that variable is not set), it still caused dash to throw up.
Changed in dash: | |
status: | Unconfirmed → Unknown |
Changed in dash: | |
assignee: | nobody → micah-cowan |
Changed in dash: | |
status: | Unknown → Unconfirmed |
Changed in dash: | |
importance: | Undecided → Medium |
Changed in dash: | |
status: | New → Fix Released |
Changed in dash: | |
status: | Fix Released → New |
Changed in dash: | |
status: | New → Fix Released |
I can confirm the same behavior on my Feisty box and also that there is no error with /bin/bash. I'll have to leave the POSIX question to someone else.