Ascii/Hex convert in bash

前端 未结 15 1479
广开言路
广开言路 2020-12-12 21:03

I\'m now doing it this way:

[root@~]# echo Aa|hexdump -v
0000000 6141 000a                              
0000003
[root@~]# echo -e \"\\x41\\x41\\x41\\x41\"
A         


        
15条回答
  •  暖寄归人
    2020-12-12 21:11

    For the first part, try

    echo Aa | od -t x1
    

    It prints byte-by-byte

    $ echo Aa | od -t x1
    0000000 41 61 0a
    0000003
    

    The 0a is the implicit newline that echo produces.

    Use echo -n or printf instead.

    $ printf Aa | od -t x1
    0000000 41 61
    0000002
    

提交回复
热议问题