Question: I have a set of valid characters [0-9a-z\_] and a variable that is assigned one of these characters. What I want to do is to be able to increment that variable to the next in the set.

If need be I can handle the "special" cases where it would increment from '9' to 'a' and 'z' to '\_', but I can't figure out how to increment letters.

```
#!/bin/bash
y=b
echo $y  # this shows 'b'
y=$((y+1))
echo $y  # this shows '1', but I want it to be 'c'

```

Answer: 
```
y=b
echo "$y"  # this shows 'b'
y=$(echo "$y" | tr "0-9a-z" "1-9a-z_")
echo "$y"  # this shows 'c'

```

Note that this does not handle the case where $y = "\_" (not sure what you want then, and in any case it'll probably require separate handling), and if $y is more than one character long it'll "increment" all of them (i.e. "10" -> "21", "09g" -> "1ah", etc).
Maybe this can be a solution:

```
a=({0..9} {a..z} _)
echo ${a[*]}
yc=11
echo ${a[yc]}
((++yc))
echo ${a[yc]}
echo ${a[++yc]}

#Alternative 
declare -A h
# Fill the has point to the next character
for((i=0;((i+1))<${#a[*]};++i)) { h[${a[i]}]=${a[i+1]};}
y=b
echo $y, ${h[$y]}

```

Output:

```
0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z _
b
c
d
b, c

```