8.20 How Many Backslashes?
The problem with backslashes is that many different programs use them as quoting characters. As a result, it's difficult to figure out how many backslashes you need in any situation.
Here's an example, taken from System V Release 4. (Notice that I'm using the standard System V version of echo from /bin/echo . SVR4 has four versions of echo !)
In the first case, the shell uses the backslash to
the following space character.
The space before the backslash is a word separator.
gets two arguments: "
In the second case, the shell converts
In the third case, the shell converts each pair of backslashes into a
backslash, and runs the command
The terminal driver ( 42.1 ) is also capable of "eating" backslashes if they appear before special characters. If a backslash precedes the "erase" character (normally CTRL-h) or the "kill" character (normally CTRL-u), the terminal driver will pass the control character to the shell, rather than interpreting it as an editing character. In the process, it "eats" the backslash. So if you type:
The shell receives the line
What's the point of this article? Well, backslashes are messy. The shell, the terminal driver, echo (sometimes), and several other utilities use them. If you think very carefully, you can figure out exactly what's consuming them. If you're not of a rigorous frame of mind, you can just add backslashes until you get what you want. (But, obviously, the non-rigorous approach has pitfalls.) I've seen situations in troff ( 43.13 ) (which is another story altogether) where you need eight backslashes in order to have a single backslash left at the point where you want it!
What happens when you put quotes (