如何使用Bash和/或常见的Linux命令行实用程序将文本字符串转换为UTF-8编码的字节?例如,在Python中可以做到:
"Six of one, ½ dozen of the other".encode('utf-8')
b'Six of one, \xc2\xbd dozen of the other'
有没有办法在纯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'