Shell program to read two numbers and display all the odd numbers berween those two number
Posted in Academic » Decision Making
#!/bin/bash # Shell program to read two numbers and display all the odd # numbers berween those two number # ----------------------------------------------- # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ------------------------------------------------------------------------- echo -n "Enter first number : " read n1 echo -n "Enter second number : " read n2 if [ $n2 -gt $n1 ]; then for(( i=$n1; i<=$n2; i++ )) do # see if it is odd or even number test=$(( $i % 2 )) if [ $test -ne 0 ]; then echo $i fi done else echo "$n2 must be greater than $n1, try again..." fi
Download - Email this to a friend - Printable version
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: bash shell, for command, for loop, loop method, odd numbers, read command, shell loops, shell program, shell script ~ Last updated on: April 8, 2008

