bash nested single quotes

Transfer: https://blog.jysoftware.com/2015/12/bash-%E6%80%8E%E4%B9%88%E5%81%9A%E5%8D%95%E5%BC%95%E5 % 8F% B7% E5% B5 % 8C% E5% A5% 97% EF% BC% 9F /

Single quotes are not nested, because the line scanning algorithm bash next encountered a single quotation mark and will be paired on a direct, no greed scanning argument.

That being the case, in fact, an alternative will be presented immediately:

 

 

This sequence provides a first closing single quotation mark, then the command line is a single quote escape character, and finally provide an open single quote, so as to solve the problem. E.g:

 

 

Check the frequency of your most frequently used commands in the shell.

In BASH, for example, a hexadecimal escape character "\ x27" to represent the single quotes are also possible, which is another way to achieve nested single quotes way single quotes.

If the direct use of "\ '" escape character what will happen? I regret to tell you that this program is to fight character, it is possible to generate a syntax error, it may pass:

 

 

The safest is the first method we propose.

Single quotes are not nested, because the line scanning algorithm bash next encountered a single quotation mark and will be paired on a direct, no greed scanning argument.

That being the case, in fact, an alternative will be presented immediately:

 

 

This sequence provides a first closing single quotation mark, followed by a single quote character command line transfers, and finally provide an open single quote, so as to solve the problem. E.g:

 

 

Check the frequency of your most frequently used commands in the shell.

In BASH, for example, a hexadecimal escape character "\ x27" to represent the single quotes are also possible, which is another way to achieve nested single quotes way single quotes.

If the direct use of "\ '" escape character what will happen? I regret to tell you that this program is to fight character, it is possible to generate a syntax error, it may pass:

 

 

The safest is the first method we propose.

Guess you like

Origin www.cnblogs.com/gongxin12/p/11363060.html