help-bash
[Top][All Lists]
Advanced

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

Re: >= and <= for string comparison


From: Ruiyang Peng
Subject: Re: >= and <= for string comparison
Date: Tue, 17 Jan 2023 13:31:49 +0800
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Thunderbird/109.0

On 2023/1/17 12:59, Peng Yu wrote:
On 1/16/23, Ruiyang Peng<rain@ryp.intirain.cc>  wrote:
On 2023/1/17 7:55, Peng Yu wrote:
OK. I never thought about that.

It is functionally equivalent, but not as readable as >= and <=.

For the same logic, for arithmetic operators, we could use ((! (x< y)
)) and ((! (x > y) )). But there are still >= and <= for arithmetic
operators. Why don't have >= and <= for strings?

On 1/16/23, Kerin Millar<kfm@plushkava.net>  wrote:
On Mon, 16 Jan 2023 12:01:12 -0600
Peng Yu<pengyu.ut@gmail.com>  wrote:

string1 < string2
                True if string1 sorts before string2 lexicographically.

         string1 > string2
                True if string1 sorts after string2 lexicographically.

According to the manual, >= and <= are not available for string
comparison. But if >= and <= are available for arithmetic expression.
Why >= and <= can not be introduced for string comparison? Currently,
as a walkaround, I have to use > and = for >=, and < and = for <=. It
is rather cumbersome to write bash code in this way.
This is not a response to the question itself but the penultimate
sentence
isn't true. [[ ! str1 < str2 ]] and [[ ! str1 > str2 ]] would also do.

--
Kerin Millar
I think it would be simple to add support for >= and <=, and would also
unify operations on strings with arithmetic operations.  I haven't
figured out what problem this could cause just yet.  I think the biggest
reason why bash didn't add this is that it's not very usefu
It could be a reason.

But it takes more effort to find out that it is not available when it
is counter-intuitive not to provide string operations but arithmetic
operations. In this sense, it is better to add >= <= for string
comparisons to make the interface uniform. After all, it should be
straightforward to add support of >= and <= on the current framework.

I agree with you.

It might take a little while to realize that bash doesn't provide >= and <=

for strings but adding it to bash is much faster. So I thought it would be

worth posting this as a suggestion to bug-bash.

--

Ruiyang Peng


reply via email to

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