I have a variable x=7
and I want to echo it plus one, like echo ($x+1)
but I'm getting:
bash: syntax error near unexpected token `$x+1'
How can I do that?
I have a variable x=7
and I want to echo it plus one, like echo ($x+1)
but I'm getting:
bash: syntax error near unexpected token `$x+1'
How can I do that?
No need for
expr
, POSIX shell allows$(( ))
for arithmetic evaluation:See §2.6.4
echo $((x+1)) also same result as echo $(($x+1))
You can also use the
bc
utility: