且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Linux shell 中将十六进制转换为 ASCII 字符?

更新时间:2022-11-16 15:05:54

echo -n 5a | perl -pe 's/([0-9a-f]{2})/chr hex $1/gie'

请注意,这不会跳过非十六进制字符.如果您只想要十六进制(原始字符串中没有空格等):

Note that this won't skip non-hex characters. If you want just the hex (no whitespace from the original string etc):

echo 5a | perl -ne 's/([0-9a-f]{2})/print chr hex $1/gie'

此外,zshbashecho 中原生支持:

Also, zsh and bash support this natively in echo:

echo -e 'x5a'