Write a shell script which adds up 10 numbers entered by the user and displays the result to the screen. You must use the “read” command to obtain the numbers from the user.
输入10个任意的数字,使它们进行相加,输出和
#!/bin/bash
read -p “Please input the first number:” n1
read -p “Please input the second number:” n2
read -p “Please input the third number:” n3
read -p “Please input the forth number:” n4
read -p “Please input the fifth number:” n5
read -p “Please input the sixth number:” n6
read -p “Please input the seventh number:” n7
read -p “Please input the eighth number:” n8
read -p “Please input the ninth number:” n9
read -p “Please input the tenth number:” n10
val=expr ${n1} + ${n2} + ${n3} + ${n4} + ${n5} + ${n6} + ${n7} + ${n8} + ${n9} + ${n10}
echo “The result is ${val}”