9

shell中实现字母与ASCII码之间的转换

 3 years ago
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.
neoserver,ios ssh client
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
2018-08-04 2018-08-04 编程之旅 lujun9972

Related Issues not found

Please contact @lujun9972 to initialize the comment

Generated by Emacs 27.x(Org mode 9.x)

Copyright © 2014 - 2021 lujun9972   -   Powered by EGO
Themed with emacs_love


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK