1

Here's my test code:

a=1
echo $a
echo `let ++a`
echo $a

The output that I see is 1, 1. Why doesn't the third line modify the value of a?

4

because `...` equivalent to $(...), which is a subshell. changing variables in subshell are lost when the subshell closes.

0

You can increment a variable like this:

a=1
((a++))
echo $a
2

Which is more like "C-style" incrementing, instead of:

let a++

See Ipor Sircer's answer as to why your method didn't work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.