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.

Similar Reads

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:...

Variable Substitution:

The shell allows us to manipulate the value of a variable based upon its initialization status....

Command Substitution:

Command substitution is a mechanism that is followed by programmers in a bash script. In this mechanism, the output of a command replaces the command itself. Bash operates the expansion by executing a command and then replacing the command substitution with the standard output of the command. In simple words, the output of a UNIX command is bundled and then used as a command....

Contact Us