I'm trying to define a bash function returning an incremented id that I can access directly using bash substitution:
#!/bin/bash
getId() {
echo "$x"
x=$((x+1))
}
x=0
echo "id1: $(getId)"
echo "id2: $(getId)"
However the variable is not incremented and I cannot figure out why.
id1: 0 id2: 0
Please, does someone have an explanation for this behaviour?