Bash - get specific character from the string

Hi!

If I want to extract a character from a specific position of a string, I can use ${string:1:1} (if I want character at the position 1). How can I do the same thing, when the number of position is contained in the variable? ${string:$var:1}doesn't work, unfortunately.

Thanks in advance.

It ought to work. Try ${STR:${VAR}:1}

It works, just keep in mind character list is zero-based or use:

${STR:${VAR}-1:1}