Shell script for using modulo operator, finding if number is dividable and print remainder.

Following shell script helps to understand how to use modulo operator in bash and identify if number is completely dividable by another number and print the remainder.
This script accepts two arguments on the commands line, first number is Divident and second number is Divisor.

 $ vim 
echo "Module operation of $NUMBER%$DIVIDE_BY is $remainder"

if [ $remainder == "0" ]
    echo "$NUMBER: is completely dividable by $DIVIDE_BY"
    echo "$NUMBER: is not dividable by $DIVIDE_BY"

Now, lets assume we want to divide 10 by 2 first and 10 by 3 next.

 $ bash 10 2
Module operation of 10%2 is 0
10: is completely dividable by 2
 $ bash 10 3 
Module operation of 10%3 is 1
10: is not dividable by 3
Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply / Ask Question