在bash单引号和双引号之间的区别 [英] Difference between single and double quotes in bash

查看:138
本文介绍了在bash单引号和双引号之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash shell脚本,就是单引号()和双引号(之间的区别,)?

In Bash shell scripting, what is the difference between single quotes ('') and double quotes ("")?

推荐答案

单引号将不插任何东西,但是双引号将(例如变量,反引号,某些 \\ 逃逸,等...)

Single quotes won't interpolate anything, but double quotes will (for example variables, backticks, certain \ escapes, etc...)

Bash的手册已经这样说的:

The Bash manual has this to say:

3.1.2.2单引号

在单引号字符放在(''')preserves引号内的每个字符的字面意义。单引号不能包含在单引号,即使$ P $一个反斜杠pceded。

Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

3.1.2.3双引号

双引号引起的字符()preserves引号内的所有字符的字面意义,$之外,''','\\',并且,如果启用了历史扩展!,字符'$'和'''保留双引号(见shell扩展)反斜杠保留其后面只有当下列字符中的一个特殊的含义内的特殊含义:'$',''' ,','\\',或换行符。在双引号,那后面是这些字符中的一个反斜杠被除去了。反斜线preceding字符没有特殊的含义保持不变。双引号可以用$ P $双引号用反斜杠pceding它内被引用。如果启用,历史扩展将除非执行!出现在双引号使用反斜杠转义。反斜线preceding的!不会被删除。

Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘`’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed.

特殊参数'*'和'@'有特殊的含义,当在双引号(见壳牌参数扩展)。

The special parameters ‘*’ and ‘@’ have special meaning when in double quotes (see Shell Parameter Expansion).

这篇关于在bash单引号和双引号之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆