Please use [code][/code]
tags around your code, to preserve formatting and to improve readability. It would help to see what's going on here.
According to the bash man page:
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, \, and,
when history expansion is enabled, !. The characters $ and ` retain
their special meaning within double quotes. The backslash retains its
special meaning only when followed by one of the following characters:
$, `, ", \, or <newline>. A double quote may be quoted within double
quotes by preceding it with a backslash. If enabled, history expansion
will be performed unless an ! appearing in double quotes is escaped using
a backslash. The backslash preceding the ! is not removed.
echo [-neE] [arg ...]
Output the args, separated by spaces, followed by a newline. The
return status is always 0. If -n is specified, the trailing
newline is suppressed. If the -e option is given, interpretation
of the following backslash-escaped characters is enabled. The -E
option disables the interpretation of these escape characters, even
on systems where they are interpreted by default. The xpg_echo shell
option may be used to dynamically determine whether or not echo
expands these escape characters by default. echo does not interpret --
to mean the end of options. echo interprets the following escape
\a alert (bell)
\c suppress further output
\e an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\0nnn 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)
So it seems that when inside double-quotes, the shell only reduces \\, \$, \`, \", and \<newline>. All other backslash combinations are passed as is. Then echo -e
similarly processes only the patterns listed above.
In all of your lines above, the last character on the line is a space, so what you're really seeing is a literal "\ " combination. Try replacing the space with some other character, and/or bracket the results, to see it more clearly. Also, use the plain echo
command to see what the shell is really executing before the -e
interpretation further reduces it.
$ echo "[\\\\S]"
$ echo -e "[\\\\S]"
$ echo "[\\\\\S]"
$ echo -e "[\\\\\S]"
$ echo "[\\\\\\S]"
$ echo -e "[\\\\\\S]"
Finally, don't forget that single quotes protect all characters from the shell, so you can use them instead to feed echo the literal string you want to print, rather than trying to figure out how many backslashes to use.