This shell script reads three numbers from the keyboard and determines the smallest number. It first checks if the numbers are equal, and if not, it compares the first two numbers to set variables for the smallest and second smallest. It then compares the smallest variable to the third number and updates the variables if the third number is smaller. Finally, it prints the smallest number.
Original Description:
Unix shell script that finds smallest of three numbers which are read from the user
Original Title
Shell Script to Find the Smallest of Three Numbers
This shell script reads three numbers from the keyboard and determines the smallest number. It first checks if the numbers are equal, and if not, it compares the first two numbers to set variables for the smallest and second smallest. It then compares the smallest variable to the third number and updates the variables if the third number is smaller. Finally, it prints the smallest number.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
This shell script reads three numbers from the keyboard and determines the smallest number. It first checks if the numbers are equal, and if not, it compares the first two numbers to set variables for the smallest and second smallest. It then compares the smallest variable to the third number and updates the variables if the third number is smaller. Finally, it prints the smallest number.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online from Scribd
# Write a shell script to find smallest of three numbers that are read from the keyboard. #!
/bin/bash echo read read read "Enter 3 number" a b c
if [ $a -eq $b -a $b -eq $c ] then echo "All numbers are equal" exit fi if [ $a -lt $b ] then s1=$a s2=$b else s1=$b s2=$a fi if [ $s1 -gt $c ] then s2=$s1 s1=$c fi echo "smallest number is $s1"