bash - Convert ascii code to hexadecimal in UNIX shell script - Unix & Linux Stack Exchange

PHOTO EMBED

Sun Jul 10 2022 13:14:59 GMT+0000 (Coordinated Universal Time)

Saved by @xiaomian #bash

function hex() {
    printf "%%%02x\n" "'$1"
}

hex -   # Outputs %2d
hex _   # Outputs %5f
hex .   # Outputs %2e
content_copyCOPY

https://unix.stackexchange.com/questions/1316/convert-ascii-code-to-hexadecimal-in-unix-shell-script