How do I assign x the value of x + 1? I can do it in other languages but can't figure it out in bash.
I just tested two different ways and both worked for me:
@Bandit's answer is fine, but I want to highlight the difference that "let" and (( )) make to normal shell syntax:
causes bash (or ksh, or any POSIX shell) to treat the expression as an "arithmetic evaluation" in which the referenced variables don't need to be preceeded with "$". One advantage of using (( )) is that otherwise-special tokens don't need to be quoted or escaped, e.g. "*" for multiplication as in:
I find this syntax slightly clearer than $(( )) which uses the output of the expression, e.g.