[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
test -lt inconsistent about white space
From: |
Paul Eggert |
Subject: |
test -lt inconsistent about white space |
Date: |
Sat, 28 Oct 2023 12:08:05 -0700 |
User-agent: |
Mozilla Thunderbird |
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.
0001-fix-inconsistency-when-parsing-integers.patch
Description: Text Data
Re: test -lt inconsistent about white space, Martin D Kealey, 2023/10/29
Re: test -lt inconsistent about white space, Chet Ramey, 2023/10/30