I want to do something like this:
if [ $1 % 4 == 0 ]; then
...
But this does not work.
What do I need to do instead?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
(( ))operator evaluates expressions as C arithmetic, and has a boolean return.Hence,
(( 0 ))is false, and(( 1 ))is true. [1]The
$(( ))operator also expands C arithmetic expressions, but instead of returning true/false, it returns the value instead. Because of this you can test the output if$(( ))in this fashion: [2]But this is tantamount to:
if (function() == false). Thus the simpler and more idiomatic test is:[1]: Modern bash handles numbers up to your machine’s
intmax_tsize.[2]: Note that you can drop
$inside of(( )), because it dereferences variables within.