Sem as aspas, \x
é analisado pelo shell para se tornar apenas x
:
$ printf "%s\n" echo -e \xaa
echo
-e
xaa
$ printf "%s\n" echo -e "\xaa"
echo
-e
\xaa
Veja man bash
, seção QUOTING
:
A non-quoted backslash (\) is the escape character. It preserves the
literal value of the next character that follows, with the exception of
<newline>. If a \<newline> pair appears, and the backslash is not
itself quoted, the \<newline> is treated as a line continuation (that
is, it is removed from the input stream and effectively ignored).
Seu grep
é enganoso:
$ man echo | grep -o \xHH
xHH
grep -o
imprime exatamente os caracteres correspondentes, o que indica que grep
nunca recebeu \
.
A menos que você execute /bin/echo
ou env echo
, o echo
incorporado do shell será executado. Portanto, se você quiser verificar a documentação, execute help echo
ou procure em man bash
. man echo
é para /bin/echo
:
$ echo --help
--help
$ env echo --help
Usage: echo [SHORT-OPTION]... [STRING]...
or: echo LONG-OPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version output version information and exit
If -e is in effect, the following sequences are recognised:
\ backslash
...
Veja man bash
, seção SHELL BUITLIN COMMANDS
:
echo interprets the following escape sequences:
\a alert (bell)
\b backspace
\c suppress further output
\e
\E an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\ backslash
$ printf "%s\n" echo -e \xaa
echo
-e
xaa
$ printf "%s\n" echo -e "\xaa"
echo
-e
\xaa
nnn the eight-bit character whose value is the octal value
nnn (zero to three octal digits)
\xHH the eight-bit character whose value is the hexadecimal
value HH (one or two hex digits)