To explain the reason for:
echo '\\\\' output: \\
echo "\\\\" output: \
First we have to understand that when an unix command is called to be
executed, there is always two evaluations:
1) From the running shell.
2) From the unix command itself.
As an example:
rm abc*
The "rm" command only does a delete on a list of files, it does not do
anything else besides the actual delete, in other words, there is no
evaluation of file names.
When the command "rm abc*" is typed, the following happens:
1) The shell first translate "abc*", searching for all local files that begin
with "abc" and sends the entire list of files to the "rm" command.
2) The "rm" command sees a list of files to be deteled and does its job.
rm abc*
is the same as
rm "abc*"
and both are different from:
rm 'abc*'
If a local directory has the following files:
abc
abcdef
123abc
abc123
xyzabc
When rm abc* or rm "abc*" is entered, the shell searches the current
directory for files beginning with "abc" and send the following list of files
to the "rm" command to be deleted:
abc
abcdef
abc123
When rm 'abc*' is entered, the shell searches does not do any translation
of what is inside of the single quote and sends the following to "rm":
abc*
Since there is no file in the directory named "abc*", nothing is deleted!
The same applies for the "echo" command and the quotes.
Single quote ('): Everything inside is taking literally. In other words, the shell
sends the string the way it is without any translation to the unix command,
ie "echo", "sed", "rm", etc.
Double quote ("): Shell does a translation for what is inside.
Thus:
echo "\" --> Shell escape the second ", opens an input and waits for the
___________string to be closed with another ".
___________"echo" sees one double quote and whatever is typed.
echo '\' --> Shell keeps what is inside and
___________"echo" sees only one \.
echo "\\" --> Shell converts what is inside into one \ because of escape \
___________"echo" sees only one \.
echo '\\' --> Shell keeps what is inside and
___________"echo" takes the first \ as escape for the next character and
___________considers only one \.
From these values, you can explain any combination.