Timeline for Shell: why [ -n "${VAR-}" ] instead of [ -n "$VAR" ]?
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 16, 2017 at 8:21 | comment | added | ilkkachu | It's not the best choice of word, I agree. But luckily they do at least define the null string, so there's that. (Even though it's just a referral to the empty string, eh.) | |
| Jun 15, 2017 at 5:17 | history | edited | Greg A. Woods | CC BY-SA 3.0 |
${var-} isn't deprectated
|
| Jun 15, 2017 at 5:10 | comment | added | Greg A. Woods | Ah, my mistake -- my reference to the 2004 edition was incomplete. (I wish POSIX hadn't used the word "null" to refer to an empty shell variable. To most programmers with experience with pointers (or SQL for that matter) "null" means un-set, and "empty" is, well, empty.) | |
| Jun 15, 2017 at 4:37 | comment | added | ilkkachu | @GregA.Woods, IEEE Std 1003.1-2008, 2016 Edition, Shell Command Language/Parameter Expansion. There's a nice table of the eight similar forms. The manuals for some shells are a bit more vague on it, e.g. Bash's manual only mentions in the middle of the text what happens if the colon is omitted. | |
| Jun 15, 2017 at 4:33 | history | edited | Greg A. Woods | CC BY-SA 3.0 |
mention set -u
|
| Jun 15, 2017 at 4:17 | comment | added | Greg A. Woods |
Well, there's been no mention of ${VAR-} in POSIX since at least 1003.1-2004. It's not in the 10th Edition Research Unix manual either, and that came out in 1989.
|
|
| Jun 15, 2017 at 4:11 | comment | added | ilkkachu |
${VAR:-foo} and ${VAR-foo} are not the same, and there's no reason to think one is deprecated. (Okay, fine, with an empty default value, there's no difference.)
|
|
| Jun 15, 2017 at 4:10 | comment | added | ivan |
Is ${VAR-} really deprecated? It's behavior differs from the :- version if VAR is set to null.
|
|
| Jun 15, 2017 at 3:41 | history | answered | Greg A. Woods | CC BY-SA 3.0 |