help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Testing Whether $@ Is Empty Or Null


From: Chet Ramey
Subject: Re: Testing Whether $@ Is Empty Or Null
Date: Tue, 11 Oct 2022 10:16:21 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1

On 10/11/22 1:00 AM, Jessie Saenz wrote:
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

`['  is a builtin, so the arguments undergo word expansion before it's
invoked.

"$@" expands to nothing when there are no positional parameters.

The command ends up being `[ -n ]', which is true because there is one
non-null argument to `['.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]