Okay here is my code you can probably get the jist of what I'm trying to do. I'm not that good with Linux bash.
#random numbers
MAXCOUNT=100
count=1
while [ "$count" -le $MAXCOUNT ]; do
number[$count]=$RANDOM
let "count += 1"
done
#adding function
function sum()
{
echo $(($1+$2))
}
#main section
first="${count[1-20]}"
echo "The sum of the first 20 elements are: $first"
last="${count[1-20]}"
echo "The sum of the last 20 elements is: $last"
if [ $first -gt $last ]; then
echo "The sum of the first 20 numbers is greater."
else
echo "The sum of the last 20 numbers is greater."
fi
My goals with this script:
Get and echo the sum of the first 20 numbers of the array containing randoms numbers.
Get and echo the sum of the LAST 20 numbers of the array containing randoms numbers.
Echo whether the first sum is greater than the second sum.
Any help would this would be great! Bash please.