0

I'm Getting a "Too many arguments" error in a shell script. Can anyone explain me the cause of the error? Thank You.

Here is the code: #!/bin//bash -x read -p "Enter a year: " year if [ $(( $year % 4 )) -eq 0 -a $(( $year % 100 )) -ne 0 ] -o [ $(( $year % 400 )) -eq 0 ] then echo "The year is a leap year" else echo "The year is not a leap year" fi

5th Jul 2020, 5:29 PM
Anurag Mondal
Anurag Mondal - avatar
4 Answers
+ 2
Anurag Mondal I guess it happens because the string is split to multiple arguments. Using " we can hold it together.
10th Jul 2020, 2:40 PM
Lijo M Loyid
Lijo M Loyid - avatar
+ 2
Try wrapping variable output in double quotes
9th Jul 2020, 9:08 PM
Lijo M Loyid
Lijo M Loyid - avatar
0
Yes I finally figured it out. Can you explain why I need to do it? Lijo M Loyid
10th Jul 2020, 4:34 AM
Anurag Mondal
Anurag Mondal - avatar
0
Oh okay..thanks...but in the above case the input is of integer type...why is it still throwing me an error? Lijo M Loyid
10th Jul 2020, 4:05 PM
Anurag Mondal
Anurag Mondal - avatar