Substitution of escape sequences

There are some sequences of characters that don’t represent their true nature but they have special meaning to the operating system and these sequences are known as escape sequences. When they are used in a command, they are replaced by actual values.

Escape Sequences Significance
\n add a new line
\t horizontal tab
 \\ backslash
\b backspace
\r carriage return

Example:

In this script, we used two echo commands to print strings. As you can see we have used an escape sequence for the new line (\n) at the end of the string. Since the actual job of this character is to add a new line hence new line is added (clearly visible in the output). Also, in the second statement, we have used three horizontal tab characters in the beginning.  Since the actual job of this character is to add a horizontal tab space hence three horizontal spaces are added before printing the string to console (clearly visible in the output).

#!/bin/sh

#statement 1
echo -e "w3wiki\n"

# statement 2 
echo -e "\t\tis the best"

Output:

Shell Scripting – Variable Substitution

A shell is an interface that helps users to connect with the system. Using a shell is equivalent to indirectly communicating with the operating system. In Linux distributed systems, each time we use a terminal, we connect with a shell. The job of a shell is to analyze Unix commands or instructions given by the user. This process involves taking commands from the user and converting them into a form that the kernel can easily understand. In simple words, it acts as a medium between the user and the kernel of the operating system. The kernel is the most crucial part of a computer’s operating system.

In order to understand variable substitution, let us first discuss substitution in shell scripts. Substitution is a functionality by following which we can instruct the shell to substitute the actual value of an expression.

Similar Reads

Substitution of escape sequences:

There are some sequences of characters that don’t represent their true nature but they have special meaning to the operating system and these sequences are known as escape sequences. When they are used in a command, they are replaced by actual values....

Variable substitution:

A shell allows us to manipulate the value of a variable based upon its initialization status. By initialization status we mean, whether a variable is initialized before its value is actually used for different purposes....

Contact Us