Backslashes and ANSI-C quoting
How it works
Outside quotes, a backslash protects the next character from its ordinary shell interpretation, except that a backslash followed immediately by a newline removes both characters. Within double quotes, backslash has special meaning before $, backtick, double quote, backslash and newline; before ordinary letters it remains literal. Bash also supports ANSI-C quoting ($'...'), where escapes such as \n and \t produce actual newline and tab characters. This is different from printf interpreting escapes in its format string.
Run each example separately in a fresh noninteractive Bash script with default options. Tested on Bash 5.2.37 with C locale. Do not enter the prompt or the expected output as code.
Escape a space and dollar
Expected stdout (tabs are real characters):
[daily report][$5]The first backslash protects the space; the second prevents expansion of the dollar sign.
Continue a line
Expected stdout (tabs are real characters):
onetwoThe backslash-newline pair disappears before token recognition. Indentation here separates the arguments; it is not printed.
Actual tab versus literal backslash
printf '%s\n' $'name\tscore' $'Sara\t9'printf '%s\n' "name\tscore"Expected stdout (tabs are real characters):
name scoreSara 9name\tscoreThe first two lines contain actual tabs. The third contains a literal backslash and t; double quotes do not interpret backslash-t.
Common mistakes
A space after a continuation backslash prevents it from escaping the newline. Do not use "\n" expecting Bash to create a newline; use $'\n' for an actual newline in a value. Bash variables cannot represent embedded NUL bytes.
Practice
Print the literal text Total: $8, then use ANSI-C quoting to print A and B separated by a real tab.
Next: Preserve spaces and empty arguments