鉴于:
$ printf "love" | od -td4 -A n
1702260588
$ printf "lovehate" | od -td8 -A n
7310575196135911276
Bash中是否有简洁(理想情况下没有循环,awk,sed,perl或python)方式将数字1702260588
和7310575196135911276
转换为love
和lovehate
分别?
答案 0 :(得分:4)
以下是我提出的建议:
alpha() {
(($1)) && printf "\x"$(printf "%02x" $(($1%256)))$(alpha $(($1/256)))"\n"
}
alpha 1702260588
alpha 7310575196135911276
输出:
love
lovehate
编辑:这是使用xxd
实用程序的答案:
# The echo is only necessary to get a newline at the end.
echo $(printf "%x" 1702260588 | xxd -r -p | rev)
echo $(printf "%x" 7310575196135911276 | xxd -r -p | rev)
输出:
love
lovehate