bug-bash
[Top][All Lists]
Advanced

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

Re: [bash 4] 'test -v 1' is never true


From: Alex Colomar
Subject: Re: [bash 4] 'test -v 1' is never true
Date: Mon, 28 Nov 2022 23:39:53 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3

Hi Martin,

On 11/27/22 17:53, Martin D Kealey wrote:
The expansion `$[var+replacement}` was part of the Bourne shell when I used it in 1985 (before POSIX was first published),

I didn't know that; interesting. Still looks ugly/convoluted to me to use that feature here. Might be useful if I didn't had another tool...

whereas `test A -gt B` is rather newer,

Being POSIX, it's old enough for my taste :)

and `test -v` is only a Bash extension (and similarly wasn't added until later).

Yeah, I started using that for consistency with other -v tests. In fact, the first time I used it instead of $#, I wasn't sure if it would work.

I think $# wins for me.

Thanks!

Alex


The man and info pages have retained the rather terse descriptions of those oldest expansions, and they are buried in the sheer volume of the current documentation.


On Sun, 27 Nov 2022 at 23:00, Alejandro Colomar <alx.manpages@gmail.com <mailto:alx.manpages@gmail.com>> wrote:

    Hi Alexey,

    On 11/27/22 12:41, Alexey wrote:
     > On 2022-11-26 21:45, Alejandro Colomar wrote:
     >> That was my gut; thanks!  I'll workaround with $#.
     >
     > I could suggest you to use for clarity another construction:
     > [[ ${1+isset} ]] || echo "not set"
     >
     > Here "isset" is just for readability. You could place any other
    string literal
     > there.

    I actually find that very confusing.  What feature is it using?  I
    couldn't find
    it with `info bash | less` then `/\+`.

          test $# -ge 1

    has the benefit that it's just a sed(1) away from my old

          test -v 1

    And it only needs the following to be understood:

          man test | grep -A1 ' -ge '
          man sh | grep '   # '

    The old version (test -v 1) required:

          help test | grep ' -v '
          man sh | sed -n '/^   Positional/,/^$/p'

    Both are easy to find.

     >
     > Regards,
     > Alexey.

    Cheers,

    Alex

-- <http://www.alejandro-colomar.es/ <http://www.alejandro-colomar.es/>>


--
<http://www.alejandro-colomar.es/>

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

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