Printing the largest number in a bash or ksh shell array
I was in need of a shell sort script that allowed me me to print out the largest number in a ksh or bash shell array.
The following example displays how to print the the number of lines from a file in your home directory with the largest number of lines.
#!/bin/bash
counter=0
STARTT=( `find $home -type f -exec wc -l {} \; | cut -f 1 -d " " ` )
big=${STARTT[0]}
while [ ${STARTT[$counter]} ]; do
if [ $big -lt ${STARTT[$counter]} ]; then
big=${STARTT[$counter]}
fi
let counter=$counter+1
done
echo "of $counter items the largest is: $big"
0 Comments:
Post a Comment
<< Home