#
minmax.sh
# Program : Assume there is
a file “Numbers” with some integers, write a shell script to find maximum and
minimum integer in that file or not.
# Author : 141740
# Date : 17/03/2015
max=`cut
-d ' ' -f1 numbers`
min=`cut
-d ' ' -f1 numbers`
for num
in `cat numbers`
do
if [ $num -gt $max ]
then
max=$num
fi
done
for num
in `cat numbers`
do
if [ $num -lt $min ]
then
min=$num
fi
done
echo
"The max elements is $max"
echo
"The min element is $min"
Output:
[141740@localhost
~]$ cat numbers
10 20 30
40 50
[141740@localhost
~]$ sh minmax.sh
The max
elements is 50
The min
element is 10
[141740@localhost
~]$
i got some error
ReplyDelete