$ str="hello"
$ hex="$(printf '%s' "$str" | xxd -p -u)"
$ echo "$hex"
68656C6C6F
Or:
$ hex="$(printf '%s' "$str" | hexdump -ve '/1 "%02X"')"
$ echo "$hex"
68656C6C6F
Careful with the '"%X"'
; it has both single quotes and double quotes.
$ str="hello"
$ hex="$(printf '%s' "$str" | xxd -p -u)"
$ echo "$hex"
68656C6C6F
Or:
$ hex="$(printf '%s' "$str" | hexdump -ve '/1 "%02X"')"
$ echo "$hex"
68656C6C6F
Careful with the '"%X"'
; it has both single quotes and double quotes.