Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result.
sum=0
if [ $# -eq 0 ]
then
read -p "Enter first number: " num1
read -p "Enter second number: " num2
sum=$(( $num1 + $num2 ))
else
for i do
sum=$(expr $sum + $i)
done
fi
echo $sum
Get Answers For Free
Most questions answered within 1 hours.