Skip to content

Commit

Permalink
test: exit(1) for no argument (#520)
Browse files Browse the repository at this point in the history
* The wording of standards document is "exit 1 if expression evaluates to false, or if expression is missing"
* A usage example might be "[ $xyz ]" in a shell script; unquoted variable will substitute to empty string if not set so no argument is passed to test command
* 4 different versions of test exit(1) consistently for this case: pdksh builtin, bash builtin, /usr/bin/test on Linux and /bin/test on OpenBSD

1. https://pubs.opengroup.org/onlinepubs/009695399/utilities/test.html
  • Loading branch information
mknos committed Mar 25, 2024
1 parent 52792d7 commit e8e8dac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/test
Expand Up @@ -228,7 +228,7 @@ sub test (@) {
return ($@) ? undef : 0+$result;
}

exit(2) if (@ARGV == 0);
exit(1) if (@ARGV == 0);
my $rc = test @ARGV;

## For command-lines, zero is success and non-zero is false, so
Expand Down

0 comments on commit e8e8dac

Please sign in to comment.