URL: <https://savannah.gnu.org/bugs/?66363>
Summary: "test" builtin command, -a arg not working as expected Group: The GNU Bourne-Again SHell Submitter: None Submitted: Mon 21 Oct 2024 10:18:53 AM UTC Category: None Severity: 3 - Normal Item Group: None Status: None Privacy: Public Assigned to: None Open/Closed: Open Discussion Lock: Any _______________________________________________________ Follow-up Comments: ------------------------------------------------------- Date: Mon 21 Oct 2024 10:18:53 AM UTC By: Anonymous $ test -n "" -a x -ge 4 bash: test: x: integer expression expected In the above shown, output, bash correctly reports that "x" isn't right as it expects an integer on the left hand side of the -ge arg. However, I do not expect bash to evaluate the expression on the right side of the -a arg as the left side of the -a arg should always evaluate to false (therefore the right side expression should not be evaluated, IMO). This issue came up in practice when I did something like this: $ if test -n "$2" -a "$2" -ge 4; then I was making sure an 2nd argument was supplied to my script before doing any integer comparisons on it. I ended up working around the issue by changing the line to something like: $ if test -n "$2" && test "$2" -ge 4; then I think this is the second time I've been caught out by this unexpected behavior of the test command. Cheers _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?66363> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/
signature.asc
Description: PGP signature