bug-bash
[Top][All Lists]
Advanced

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

Re: test -lt inconsistent about white space


From: Martin D Kealey
Subject: Re: test -lt inconsistent about white space
Date: Sun, 29 Oct 2023 17:43:32 +1000

I'm more concerned that the error message is misleading; "integer
expression expected" is NOT true; rather an integer LITERAL is expected
(meaning an optional sign followed by one or more digits).

As for fixing the inconsistency, I would rather get rid of whitespace
skipping entirely, perhaps with a shopt to re-enable it.

-Martin

On Sun, 29 Oct 2023 at 05:08, Paul Eggert <eggert@cs.ucla.edu> wrote:

> Consider the following shell script 'doit':
>
> sp=' '
> nl='
> '
> test "${sp}1${sp}" -lt "${sp}2${sp}"
> test "${nl}3${sp}" -lt "${nl}4${sp}"
> test "${sp}5${nl}" -lt "${sp}6${nl}"
> test "${nl}7${nl}" -lt "${nl}8${nl}"
>
> Running the command "bash doit" outputs:
>
> doit: line 6: test:  5
> : integer expression expected
> doit: line 7: test:
> 7
> : integer expression expected
>
> The problem occurs because strtoimax accepts all forms of leading
> whitespace, whereas Bash accepts only space and tab after the integer.
> This is inconsistent: Bash should treat trailing whitespace the same way
> it treats leading whitespace, and should accept all of doit's 'test'
> commands, as Dash does.
>
> Proposed patch attached.


reply via email to

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