help-bash
[Top][All Lists]
Advanced

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

Re: not sure about number comparison


From: Greg Wooledge
Subject: Re: not sure about number comparison
Date: Sun, 19 Feb 2023 14:50:16 -0500

On Sun, Feb 19, 2023 at 02:15:41PM -0500, Roger wrote:
> Any notes on POSIX compliance?  Or as it sounds if most are doing it, is it
> already considered mostly POSIX compliant?

I went out of my way to say "bash" repeatedly, because (( )) and [[ ]]
are both bash extensions.

If you have to do this in POSIX, you only have test and [ ].

if test "$x" -lt 5; then
    echo "too small"
...

In this case, you'd use -lt and friends for integer comparisons,
and = or != for string equality comparisons.

I don't believe POSIX offers a string comparison operator analogous
to bash's < and > operators inside the [[ ]] command.  So... you just
don't do that at all.



reply via email to

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