bash ascii to hex

前端 未结 5 2007
野的像风
野的像风 2020-12-28 16:45

was wondering if anyone could help me with converting ascii to hex in bash. Example code:

#!/bin/bash 
STR = \"hello\"
#Convert to hex
HEXVAL = $STR #(in hex         


        
5条回答
  •  长发绾君心
    2020-12-28 16:53

    xxd -p -u <<< "$STR" | sed 's/\(..\)/0x&, /g; s/, $//;'
    

    0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A

提交回复
热议问题