Escape sequences
An escape sequence is a group of character(s) that does not represent its actual value when it is used as a string literal. Some of the escape sequences are listed below:
Sr. No. | Escape Sequences | Significance (actual value) |
---|---|---|
1 | \n | new line |
2 | \f | form feed |
3 | \r | carriage return |
4 | \b | backspace |
5 | \t | horizontal tab |
6 | \v | vertical tab |
7 | \\ | backslash |
Shell substitutes an escape sequence with its actual value.
Example:
In this shell script, firstly we have used an echo command to print a string. Note that we have used an escape sequence ( \n ) at the end of the string. It will add a new line character after printing the string.
#!/bin/sh // Print the string echo -e "Hello World! \n" // Print the string echo -e "Hello w3wiki"
Output:
Shell Scripting – Substitution
There are certain expressions that convey special meanings. In other words, they are not what they look like. A shell carries out substitution whenever it encounters such expressions. Hence, substitution is defined as a mechanism carried out by a shell in which it substitutes the value of an expression with its actual value.
Contact Us