I'm trying to convert unicode literals into readable format. I'm using the -t flag to see what command xargs is going to run before it runs it. I see the following weirdness:
$ echo -n "\\\t\\\u0042\\\u0065\\\u006e" | xargs -t -I '{}' echo -e '"'{}'"'
echo -e "\t\u0042\u0065\u006e"
" \u0042\u0065\u006e"
Yet when I run it manually:
$ echo -e "\t\u0042\u0065\u006e"
Ben
$
The \t
is being correctly processed in both examples. but the \u00XX
values are being treated as a plain string in the first example but is being encoded correctly in the second example. I see the same weirdness when I use printf
as well.
$echo -n "\\\t\\\u0042\\\u0065\\\u006e" | xargs -t -I '{}' printf \"{}\"
printf "\t\u0042\u0065\u006e"
" printf: invalid universal character name \u0042
$ printf "\t\u0042\u0065\u006e"
Ben
Any ideas on what's happening and how to fix it?
echo
builtin? If so, try manually running$(which echo) -e "..."
-- that'll be the onexargs
is usingecho
builtin, andprintf
also. Try/bin/echo -e "\u0042\u0065\u006e"
and/bin/printf ""\u0042\u0065\u006e"
and you'll find those give the same results asxargs
var=$(echo -n "\\t\\u0042\\u0065\\u006e"); echo -e "$var".