Could someone tell me what's wrong with my shell script please?
Hi, I'm trying to write a shell script that allows the user to enter an arbitrary number of values and then returns the sum of all the values entered. The following happens when I try to run the script. Can someone tell me what I am doing wrong please? Help appreciated!
Enter the number of numbers you want to add together
6
Enter number
1
./sum3.txt: line 6: [: too many arguments
Here is my script:
#!/bin/sh
s=1
sum=0
echo "Enter the number of numbers you want to add together"
read N
while [ $s -le $N ]
do
echo "Enter number"
read D
sum='expr $sum + $D'
s='expr $s + 1'
done
echo "Answer = $sum'
|