Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15781

Re: possible bug in Bash 5.0

From Eli Schwartz <eschwartz@archlinux.org>
Newsgroups gnu.bash.bug
Subject Re: possible bug in Bash 5.0
Date 2019-12-25 23:31 -0500
Message-ID <mailman.1440.1577334721.1979.bug-bash@gnu.org> (permalink)
References <482a982b-c02b-65a3-68c5-e4c0e1f62874@uni-paderborn.de> <2351f424-162e-11ad-e762-d9fb2786f491@archlinux.org>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 12/25/19 5:41 PM, Xin Wu wrote:
> Hi,
> 
> I found the single-bracket [ ... ] and double-bracket [[ ... ]] behave
> differently for string comparison in the follow simple Bash-script.
> 
> # comma (,) is before two (2) in ASCII
> a=,rst
> b=2rst
> if [ "$a" \> "$b" ]; then
>   echo "single-bracket"
> fi
> if [[ "$a" > "$b" ]]; then
>   echo "double-bracket"
> fi
> 
> According to some web pages I was expecting that single-bracket and
> double-bracket should give same result. I'm not a Bash-expert, therefore
> I'm not sure whether this is a real bug in Bash 5.0.
> 
> Merry Christmas!
> 
> Xin
> 
> PS: the web pages are:
> 
> * http://tldp.org/LDP/abs/html/comparison-ops.html
> * http://tldp.org/LDP/abs/html/refcards.html
> * http://mywiki.wooledge.org/BashFAQ/031

On the last of these three web pages is the note:

"As of bash 4.1, string comparisons using < or > respect the current
locale when done in [[, but not in [ or test. In fact, [ and test have
never used locale collating order even though past man pages said they
did. Bash versions prior to 4.1 do not use locale collating order for [[
either."

Try using the C locale, for example: LC_COLLATE=C

Then see what the double brackets does.

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: possible bug in Bash 5.0 Eli Schwartz <eschwartz@archlinux.org> - 2019-12-25 23:31 -0500

csiph-web