Computing.Net > Forums > Unix > If to check muttiples of a value

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

If to check muttiples of a value

Reply to Message Icon

Name: nauj
Date: May 24, 2007 at 12:26:50 Pacific
OS: AIX5.1
CPU/Ram: IBM
Product: IBM
Comment:

Hi,

I want to make an if clause in UNIX to check if a value is multiple of other one.

If var <is multiple of> 3 then...

This condition is fulfilled when var is equal to 3, 6, 9, 12...

Which is the expression of UNIX to do this checking??

Any advice will be greatly apreciatted.

Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: May 24, 2007 at 14:52:26 Pacific
Reply:

In the Korn shell, you can use the modulo operator:

#!/bin/ksh

echo "enter an integer var"
read var

if [[ $(($var % 3)) -eq 0 ]]
then
echo "$var is divisible by 3"
fi


0

Response Number 2
Name: nauj
Date: May 25, 2007 at 00:57:02 Pacific
Reply:

Thank you very much for yur help


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


match strings How to get rid of null ch...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: If to check muttiples of a value

how to seach and replace a value using shell www.computing.net/answers/unix/how-to-seach-and-replace-a-value-using-shell-/8492.html

How to get rid of a "," at the end of a variable read www.computing.net/answers/unix/how-to-get-rid-of-a-at-the-end-of-a-variable-read/1186.html

how to check amount of video memory www.computing.net/answers/unix/how-to-check-amount-of-video-memory/7432.html