I am trying to write a short script that accepts a variable number of parameters (also numbers) then adds those parameters together to get a total of the numbers. Then gets an average for those numbers entered. This is what i have so far;
#!/bin/bash
count=1
ncount=1
echo
echo "please enter number of parameters: "
read parano
while [ $parano -ge $numbers$count ]
do
echo
echo "Please enter parameter $count: "
read number$ncount
let count=count+1
let ncount=ncount+1
done
Total=$((number$ncounttotal))
Average=$((Total/parano))
echo
echo "You have chosen $parano parameters"
echo
echo "The average is $Average"
echo
Its just the line for calculating the total that I am having issues with and cannot seem to find the code to calculate it. The rest seems to be working great but the average always comes out as 0 because of the total not being calculated. Anyone have any ideas?
$numbers$countandnumber$counttotal, but that doesn't work. You should probably use an array instead, see here for a detailed discussion.read, but in general you can't generate a variable name dynamically in Bash and you need indirection - but as you found out, arrays are the way to go here.