Friday, January 20, 2012

Increment in bash with unary operator ++

Probably a lot of people may know this already, but I didn't... so I might as well share it:

bash-3.2$ c=1
bash-3.2$ echo $c
1
bash-3.2$ ((c++))
bash-3.2$ echo $c
2
The trick here is the ((..)) which is used in bash for arithmetic evaluations like:

echo $((1+1))

0 comments: