I'm trying to run a very simple script that reads input from a user and continuously loop.But they show error [:too many arguments
i=0
while [ $i -le 5 ]
do
echo $i
i='expr $i + 1'
done
Change '' to Acute (`). I have tested it works fine
i=0
while [ $i -le 5 ]
do
echo $i
i=`expr $i + 1`
done
~.The error is that you're using single-quotes instead of back-quotes for your command-substitution. In other words, it should be i=`expr $i + 1` rather than i='expr $i + 1'.
Also, an @Pankrates points out, it may be more readable to use the equivalent expression i=$(expr $i + 1). Had the author of whatever material you were reading used that form, it seems safe to say that your troubles had been avoided, at least.
$()$() is more readable (and I'll edit in a note on this, thanks), but I haven't heard anything about them being considered obsolescent.$() has become the more preferable option because of its better nestability. see this bash FAQ