Reputation: 343
I am testing a simple program shell(sh).
I am using while loop but it show an error.
./essai.sh: line 5: test: too many arguments
This is the code:
#!/bin/sh
numero=1
max=3
while test [ $numero -le $max ]
do
ping -c 2 127.0.0.1
numero=$(($numero + 1))
printf $numero
sleep 5
done
Upvotes: 0
Views: 393
Reputation: 2465
"[]" means "test", So you can change that line to
while test $numero -le $max
or
while [ $numero -le $max ]
BTW: the spaces between "[]" and conditional expression is necessary.
Upvotes: 3
Reputation: 1139
The test keyword has to be removed:
while [ $numero -le $max ]
Do you know also
for numero in $(seq 1 3) ; do echo $numero ; done
Upvotes: 1
Reputation: 1330
Condition statement is wrong change condition from
while test [ $numero -le $max ]
to
while [ $numero -le $max ]
Upvotes: 1