与数字互相转换

基本类型 / 字符类型

char="A"

#printf with a quote before the character prints its code
intValue=$(printf '%d' "'$char")
#intValue is 65

intValue=$((intValue + 1))
#intValue is 66

#back: the code is turned into a \x escape and printf reads it
printf -v hexCode '%x' "$intValue"
printf -v charB "\\x$hexCode"
#charB is "B"

echo "intValue is $intValue"
echo "charB is $charB"