Chapter 1. Linux Basics

Special Characters and Escape Character

Special Characters and Escape Character
Tag:

There are characters with special meanings assigned by Linux OS called special characters. You cannot use the characters in a file name or normal text sentence. If you want to use them without having a special meaning in a sentence, you need to use an escape character.

In bash, \ (backslash) is used as an escape character.

For example, if you want to display the following sentence with the echo command, you may have difficulty showing " " (double quotes).

He said “I'm learning Linux OS”.

With " " (double quotes) around the entire sentence in the command, you won't get any returned value.

Command Line - INPUT
echo "He said "I'm learning Linux OS"."
Command Line - RESPONSE
>

Without " " around the entire sentence in the command, you get a sentence; however, " " is not shown.

Command Line - INPUT
echo He said "I'm learning Linux OS".
Command Line - RESPONSE
He said I'm learning Linux OS.

If you use a backslash like below, you can display the intended sentence in the command line.

Command Line - INPUT
echo "He said \"I'm learning Linux OS\"."
Command Line - RESPONSE
He said "I'm learning Linux OS".

There are characters with special meanings assigned by Linux OS called special characters. You cannot use the characters in a file name or normal text sentence. If you want to use them without having a special meaning in a sentence, you need to use an escape character.

In bash, \ (backslash) is used as an escape character.

For example, if you want to display the following sentence with the echo command, you may have difficulty showing " " (double quotes).

He said “I'm learning Linux OS”.

With " " (double quotes) around the entire sentence in the command, you won't get any returned value.

Command Line - INPUT
echo "He said "I'm learning Linux OS"."
Command Line - RESPONSE
>

Without " " around the entire sentence in the command, you get a sentence; however, " " is not shown.

Command Line - INPUT
echo He said "I'm learning Linux OS".
Command Line - RESPONSE
He said I'm learning Linux OS.

If you use a backslash like below, you can display the intended sentence in the command line.

Command Line - INPUT
echo "He said \"I'm learning Linux OS\"."
Command Line - RESPONSE
He said "I'm learning Linux OS".
Tag: