Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the linux escape character?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report