I am confused on this topic when reading the Advanced Bash Scripting Guide. According to the book,

Bash script, when we quote a string, we set it apart and protect its literal meaning.


Escaping is a method of quoting single characters. The escape (\) preceding a character tells the shell to interpret that character literally.

Seems that \ is a "functional" character, but what if it's also put in a double quote? Will \ be taken only as a literal or it still does escaping? For example,

echo \z  # z
echo "\z"  # \z  seems that the backslash is taken literally
echo \\  # \
echo "\\"  # \  so why this result is not \\ ?

1 Answer 1


man bash:

Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of $, `, \, [...] The backslash retains its special meaning only when followed by one of the following characters: $, `, ", \, or newline.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .