In: Computer Science
Why am I getting error below?
sh-3.2# ./week4prog1[name].scr
./week4prog1[name].scr: line 2: count: command not found
start of the program
./week4prog1[name].scr: line 4: [: -le: unary operator expected
end of the program
Below is my vim script I am running. I can't see the error, please help:
#!/bin/bash
count =1
echo "start of the program"
while [ $count -le 10 ]
do
echo "Loop #$count"
sleep 10
count=$[ count + 1]
done
echo "end of the program"
Linux is very sensitive langauage and you alweays have to care about the spaces or any other tiny errors you may get when executing a program.
Here in this program, yoiu had this error because of an additional space in line 2
count =1
This is invalid
And shoud be change to
count=1
Which fixes your problem.
#!/bin/bash
count=1
echo "start of the program"
while [ $count -le 10 ]
do
echo "Loop #$count"
sleep 10
count=$[ count + 1]
done
echo "end of the program"
Execution of the program:
I encountered ths same error just to show you. Here is the exact error when I had a space in count.
If you have any doubts, leave a comment below before rating. I'll be happy to assist you further.
Do UPVOTE this as I have put a lot of EFFORT in answering this question. It really helps me.