0

I have an expression like following in a bash script:

if test $year % 4 -eq 0

but it's throwing a warning line 5: test: too many arguments

what is the problem here? how I can fix this?

1 Answer 1

4

The test builtin doesn't do arithmetic; it doesn't understand the % notation.

If you really want to use test, then you could write:

if test $((year % 4)) -eq 0

(using arithmetic expansion; the $((year % 4)) bit gets replaced with the relevant value before test is invoked); but I think it's simpler and clearer to write:

if ((year % 4 == 0))

(using an arithmetic expression instead).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.