Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the linux escape character?

Shulou Source: shulou.com Published: 2022-05-31 11:05:12 09月27日 Update

This article will explain in detail what the linux escape character is. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Linux escape characters are: 1, backslash "\", put "\" before special characters, the original meaning of special characters will be ignored; 2, single quotation marks "'", the special meaning of characters wrapped in single quotation marks will be ignored; 3, double quotation marks "", double quotation marks will retain part of the character attributes without escape.

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Linux escape character

(1) escape character "\"

If you put "\" before the special characters, shell ignores the original meaning of those special characters

Treat them as ordinary characters, such as:

[root@WEBServer ~] # lsabc?* C:\ backup [root@WEBServer ~] # mv abc\?\ * abc [root@WEBServer ~] # mv C\:\\ backup backup

The previous section renamed abc?* to abc and C:\ backup to backup. Because of the missing pieces

The name contains special characters, so the escape character "\" is used.

(2) single quotes "'"

If you place a string between quotation marks, the special meaning of all characters in the string is ignored, for example:

[root@WEBServer ~] # mv C\:\ backup backup [root@WEBServer ~] # mv'C:\ backup' backup

The above two commands are completely equivalent

(3) double quotation marks ""

The quotation marks in double quotation marks are basically the same as those in single quotation marks, and most of the special characters enclosed in double quotation marks

Can be treated as ordinary characters, but there are still some special characters, even if enclosed in double quotation marks

Still retain their own special meanings, such as "$", "\" and "`".

[root@WEBServer ~] # str= "The\ $SHELL Current shell is $SHELL" [root@WEBServer ~] # str1= "\ $SHELL" [root@WEBServer ~] # echo $strThe $SHELL Current shell is / bin/bash [root@WEBServer ~] # echo $str1 $/ bin/bash

As you can see from the output above, "$" and "\" still retain a special meaning in double quotes.

[root@WEBServer ~] # str= "This hostname is `hostname`" [root@WEBServer ~] # echo $strThis hostname is WEBServer

In the above output, the character "`" also retains its own special meaning in double quotes.

This is the end of the article on "what is the linux escape character". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Characters quotation marks special escape meaning string article ordinary more faceted output good practical same between content package command most attributes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi OPPO Reno MariaDB Shulou Tech Info