How to convert ASCII character to integer in bash?

I'm parsing an ntpq output to pass its contents to our database via console utility. The first element is a one character substring containing status of the remote. It can be "*", "+", "o", "#" etc. I'd better put it to the DB as a number, so it can be easily held by stored procedures, but I have no idea, how to convert a character into it's ASCII representation in bash.


Solution 1:

Put your character into the variable A.

printf '%d\n' "'$A"

Some examples:

$ A="*"; printf '%d\n' "'$A"
42
$ A="+"; printf '%d\n' "'$A"
43
$ A="#"; printf '%d\n' "'$A"
35
$ A="o"; printf '%d\n' "'$A"
111