x=1
while [ $x -le 50 ]
do
echo $x
$x=(($x + 1))
done
I have wrote the above code. What seems to be a easy task in many programming languages is giving this error for me.
solution.sh: line 5: syntax error near unexpected token `('
solution.sh: line 5: ` $x=(($x + 1))'
How to debug errors in bash. Is there any IDE?
bash -x scriptname
to debug. – jherran Dec 08 '14 at 11:51x=$(($x + 1))
. But easy to useseq
instead all scriptseq 50
– Costas Dec 08 '14 at 11:52echo {1..50}
. And in$(())
environment, the variables inside are automatically evaluated, which is why you don't need the$
inside it again. – muru Dec 08 '14 at 11:55((x++))
. Also look up thelet
command. – Dec 08 '14 at 12:01$(($x+1))
that will work but(($x+1))
will not, look on http://tldp.org/LDP/abs/html/arithexp.html for more info – Dec 08 '14 at 12:03$(())
, I don't see how I am incorrect. See: https://www.gnu.org/software/bash/manual/html_node/Arithmetic-Expansion.html – muru Dec 08 '14 at 12:04