Timeline for Why does -n with unquoted variable containing empty string return true? [duplicate]
Current License: CC BY-SA 4.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 1 at 20:21 | comment | added | stevea | @ikkachu states: <<also, "$var" will only ever result in one argument (or word/field, howevery you like), never none (nor more than one) – ilkkachu>>, but this is blatantly false. Try "${!B@}" . Bash expansion is complex, with many exceptions, and marginally documented, leading to Ikkachu's understandable error. | |
Jan 1 at 1:24 | comment | added | stevea | Sigh, do you need a pointer to the man pages ? "man bash" states only "-n string True if the length of string is non-zero.". It does NOT state behavior when the 'string' argument is zero-length, is a non-string, or is absent; therefore the documentation is clearly defective. | |
Dec 28, 2023 at 16:35 | history | edited | MC68020 | CC BY-SA 4.0 |
deleted 17 characters in body
|
Dec 28, 2023 at 12:17 | comment | added | ilkkachu |
@stevea, also, "$var" will only ever result in one argument (or word/field, howevery you like), never none (nor more than one)
|
|
Dec 28, 2023 at 12:15 | comment | added | ilkkachu | @stevea, sigh... Claims like that about documentation would be much easier to accept if they came with some grounds, e.g. if you showed the piece of documentation you were reading, that didn't properly describe the behavior. See e.g. the answer under [Why isn't [ -n ] false like [ -n "" ]?](unix.stackexchange.com/q/400889/170373) (The Q I linked there). | |
Dec 28, 2023 at 12:10 | history | duplicates list edited | ilkkachu | duplicates list edited from Test -n gives unexpected result to Test -n gives unexpected result, Why isn't [ -n ] false like [ -n "" ]? | |
Dec 28, 2023 at 12:09 | comment | added | stevea | IOW -n with no argument returns true. This is not well documented. Your $var and "$var" evaluate to no-argument before /usr/bin/test is called. | |
Dec 28, 2023 at 12:09 | comment | added | ilkkachu |
@stevea, that doesn't explain much. Why would [ -n ] be relevant when they clearly had [ -n $var ] ? Why would [ -n ] be true? What does it even mean?
|
|
Dec 28, 2023 at 12:08 | history | closed | muru bash Users with the bash badge can single-handedly close bash questions as duplicates and reopen them as needed. | Duplicate of Test -n gives unexpected result | |
Dec 28, 2023 at 12:08 | comment | added | stevea | Because $ [ -n ]; echo $? 0 | |
Dec 28, 2023 at 12:06 | history | edited | pmor | CC BY-SA 4.0 |
added 24 characters in body; edited title
|
Dec 28, 2023 at 11:27 | vote | accept | pmor | ||
Dec 28, 2023 at 11:17 | history | edited | MC68020 |
edited tags
|
|
Dec 28, 2023 at 11:08 | answer | added | MC68020 | timeline score: 4 | |
Dec 28, 2023 at 10:26 | history | asked | pmor | CC BY-SA 4.0 |