Friday 26 October 2012

cmd line (biggest no , reverse)

if [ $# -ne 4 ]
then
echo "Insuffiecient command line arguments"
else
choice=1
while [ $choice -ne 4 ]
do
echo "1) Biggest of 3 nos"
echo "2) Reverse no"
echo "3) Exit"
echo "Enter your choice : "
read choice
case $choice in
1)
    if [ $1 -gt $2 -a $1 -gt $3 ]
    then
        echo "$1 is greatest no"
    elif [ $2 -gt $1 -a $2 -gt $3 ]
        then
            echo "$2 is greatest no"
    else
        echo "$3 is greatest no"
    fi
;;
2)
num=$4
rev=0
while [ $num -gt 0 ]
do
    r=$(($num%10))
    rev=$(($rev*10))
    rev=$(($rev+$r))
    num=$(($num/10))
done
    echo "Reverse no. : $rev"
;;
3)
exit
;;
*)
    echo "Invalid choice"
;;
esac
done
fi


No comments:

Post a Comment