Timeline for Test for non-zero length string in Bash: [ -n "$var" ] or [ "$var" ]
Current License: CC BY-SA 3.0
3 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 27, 2021 at 15:33 | comment | added | ingyhere |
@codeforester BASH (Bourne Again Shell) is the progeny of Bourne Shell, so it inherited the -n and -z test operators but then added the ! negation on top of it. Moreover, this is conceptually the same as the difference between == and != in higher level languages which provide affirmative and negative operators simply to expand the range of possible semantics. Sometimes it is much easier to assemble an expression that doesn't need to rely on double negatives, and so on.
|
|
Apr 15, 2018 at 5:08 | comment | added | codeforester |
Why use -n when it is not really needed in Bash?
|
|
Apr 13, 2018 at 21:47 | history | answered | papacharlie | CC BY-SA 3.0 |