abhi1610 abhi1610 - 7 months ago 10
Bash Question

Error: While loop in bash shell script

I am trying to run simple script named

test.sh
which
echo
the numbers in ascending manner. But somehow it shows error.

#!/bin/bash

clear
a= 0

while [ $a <= 5 ];
do
echo $a
a=$(( a+1 ))
done


Error:

./test.sh: line 4: 0: command not found
./test.sh: line 6: =: No such file or directory

Answer

Way better is already mentioned by Anubhava, however this is correct version of your answer.

#!/bin/bash

clear
a=0

while [[ "$a" -lt 5 ]];
do
    echo $a
    a=$(($a+1))
done