[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Testing Whether $@ Is Empty Or Null
From: |
Jessie Saenz |
Subject: |
Testing Whether $@ Is Empty Or Null |
Date: |
Mon, 10 Oct 2022 23:00:34 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 |
bash version = 5.1.16(1)-release
I do not understand why the following statement returns 0 despite no
arguments given to script:
[ -n "$@" ] && echo true
However, the following statements return 1 when no arguments are given
to script:
[ "$@" ] && echo true
var="$@"; [ -n "$var" ] && echo true
[[ -n "$@" ]] && echo true
(($#)) && echo true
Per bash Manual:
"When there are no positional parameters, "$@" and $@ expand to
nothing (i.e., they are removed)."
"-n string
True if the length of string is non-zero."
"test expr or [ expr ]
"...the expression is true if the unary test is true."
- Testing Whether $@ Is Empty Or Null,
Jessie Saenz <=