You need to include spaces :
if [ "$1" -nt limit ] || [ "$3" = "-f" ] || [ "$3" = "--force" ]; then
Failing to do that, the shell considers the inside of the test like a single argument, and by specification, with a single argument, a test returns "true" (0) if the argument is not empty.
Also, please note I quoted the $1
in the first test : if an argument is passed that contains whitespace, without quotes word splitting will occur, and the shell will see more than three arguments and fail with a syntax error (or at least not do what you want).
If you do not mind Bash-specific syntax, you could use the [[ ]]
type of test, which does not perform word splitting.
if [[ $1 -nt limit ]] || [[ $3 = -f ]] || [[ $3 = --force ]]; then
But then, by that point, you can all put them together in a single test, because this style of test also supports logical operators :
if [[ $1 -nt limit || $3 = -f || $3 = --force ]; then
Please note that the =
and !=
operators in [[ ]]
test does globbing, so the right hand side needs to be quoted if the string being tested includes something that could trigger a glob (like *).