Timeline for Why are there so many shell scripts using "x$var" = "xabc" instead of "$var" = "abc"?
Current License: CC BY-SA 4.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 21 at 7:59 | comment | added | Stéphane Chazelas |
No, it never was about empty/blank/unset $var expanding to no argument. See duplicate Q&As. That problem only occurs when you forget to quote $var, but then all sorts of values cause problems (including security vulnerabilities in shells like bash or ksh) with or without the x prefix.
|
|
| Oct 21 at 7:21 | comment | added | ilkkachu | @GiacomoCatenazzi, perhaps, but which shell would that be? | |
| Oct 21 at 6:32 | comment | added | Giacomo Catenazzi |
@davolfman: as in the answers: old shells: with simple rules "" expand to nothing, and the additional parsing step will be equivalent to put nothing. Now we handle better such case, but with much complex shell parsing rules and [ (and time) as built-in else rules we cannot handle expected behaviour. -- In past we had much more rudimental shells (and variety).
|
|
| Oct 20 at 23:22 | comment | added | davolfman | The question is why not [ "$var" = "thing" ] That does work when $var is unset, as long as the quotes are there? Is there a shell that doesn't do that? | |
| Oct 20 at 22:23 | history | answered | waltinator | CC BY-SA 4.0 |