Here's my test code:
a=1 echo $a echo `let ++a` echo $a
The output that I see is
1. Why doesn't the third line modify the value of
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
because `...` equivalent to $(...), which is a subshell. changing variables in subshell are lost when the subshell closes.
You can increment a variable like this:
a=1 ((a++)) echo $a 2
Which is more like "C-style" incrementing, instead of:
See Ipor Sircer's answer as to why your method didn't work!