Shell Script to find biggest of three numbers using command line arguments
Program
#! /bin/bash
if [ $# -ne 3 ]
then
echo "$0: Numbers are not entered"
exit 1
fi
n1=$1
n2=$2
n3=$3
if [ $n1 -gt $n2 ] && [ $n1 -gt $n3 ]
then
echo "Number 1 is biggest: $n1"
elif [ $n2 -gt $n1 ] && [ $n2 -gt $n3 ]
then
echo "Number 2 is biggest: $n2"
elif [ $n3 -gt $n1 ] && [ $n3 -gt $n2 ]
then
echo "Number 3 is biggest: $n3"
elif [ $1 -eq $2 ] && [ $1 -eq $3 ] && [ $2 -eq $3 ]
then
echo "All the three numbers are equal"
else
echo "Unable to determine"
fi
Output 1
$ chmod 755 biggest-three-numbers-command-line.sh
$ sh biggest-three-numbers-command-line.sh 46 11 26
Number 1 is biggest: 46
Output 2
$ sh biggest-three-numbers-command-line.sh 6 65 32
Number 2 is biggest: 65
Output 3
$ sh biggest-three-numbers-command-line.sh 6 12 39
Number 3 is biggest: 39
Output 4
$ sh biggest-three-numbers-command-line.sh 8 8 8
All the three numbers are equal
Output 5
$ sh biggest-three-numbers-command-line.sh 18 32 32
Unable to determine