How can a text string be turned into UTF-8 encoded bytes using Bash and/or common Linux command line utilities? For example, in Python one would do:
"Six of one, ½ dozen of the other".encode('utf-8')
b'Six of one, \xc2\xbd dozen of the other'
Is there a way to do this in pure Bash:
STR="Six of one, ½ dozen of the other"
<utility_or_bash_command_here> --encoding='utf-8' $STR
'Six of one, \xc2\xbd dozen of the other'
STR="Six of one, ½ dozen of the other", it's already basically a list of bytes (more accurately, a C string), maybe in UTF-8 encoding, maybe in something else. Tryecho "$STR" | od -x, and you'll probably see "bdc2" in the results. So I'm not really clear what you're trying to accomplish here.