9
shell中实现字母与ASCII码之间的转换
source link: https://www.lujun9972.win/blog/2018/08/04/shell%E4%B8%AD%E5%AE%9E%E7%8E%B0%E5%AD%97%E6%AF%8D%E4%B8%8Eascii%E7%A0%81%E4%B9%8B%E9%97%B4%E7%9A%84%E8%BD%AC%E6%8D%A2/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
shell中实现字母与ASCII码之间的转换 - 暗无天日
shell中实现字母与ASCII码之间的转换
shell中似乎没有直接的命令可以实现字母与ASCII码之间的转换。
不过通过printf我们还是可以做到这一点的。
ASCII码转字母:
function chr() { [ "$1" -lt 256 ] || return 1 printf "\\$(printf '%03o' "$1")" } chr 68
D
字母转ASCII码
ord() { LC_CTYPE=C printf '%d' "'$1" } ord a
97
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK