I have this code
#!/bin/bash
read num
sum=0
i=1
while [$i -le $num]; do
let sum=$sum+1
let i=$i+1
done
echo $sum
I am getting the error ./test: line 5: [1: command not found , but I am not sure what part of this is wrong and can not be found.
[ $i -le $num ]
. Note the spaces. – Kevin Oct 30 '14 at 00:41[
is a command, and it requires]
as its last argument. Note that the assignment must not have a space on either side (as you correctly have it now). – Kevin Oct 30 '14 at 00:45sum=0 i=1 while [ $i -le "$@" ]; do sum+=1 i+=1 done echo $sum
– z atef Oct 30 '14 at 01:21