击回声字符串以外的字符$ [英] Bash echo with an $ character outside the string
问题描述
谁能解释什么是
echo $"Starting $CMD"
和
echo "String $CMD"
他们似乎看起来是一样的。
They seem to look the same.
推荐答案
中查找 QUOTING
部分中的庆典
手册页:
Look up the QUOTING
section of the bash
man page:
形式的字 $字符串
被特殊处理。这个词扩展到
串,以backslash-转义替换的字符由指定
ANSI C标准。反斜杠转义序列,如果present,是德$ C $光盘作为
如下:
Words of the form
$'string'
are treated specially. The word expands to string, with backslash- escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:
- \\ A警报(钟)
- \\ b退格
- \\ E转义字符
- \\ f换
- \\ n新行
- \\ r回车
- \\ t横向标签
- \\ v纵向标签
- \\反斜杠
- \\'单引号
- \\ NNN 8位字符,其值是八进制值NNN(一到三个数字)
- \\ XHH 8位字符,它的值是十六进制值HH(一到两个十六进制数字)
- \\ CX控制-x字符
扩大的结果是单引号,好像美元符号一直没present。
The expanded result is single-quoted, as if the dollar sign had not been present.
和注意到 $
pceded后续描述双引号中的字符串$ P $( $字符串
):
And note the follow description double quoted strings preceded by $
($"string"
):
一个美元符号($)pceded双引号字符串$ P $会导致串
根据当前的语言环境进行翻译。如果当前语言环境是C
或者POSIX,美元符号将被忽略。如果该字符串翻译
更换,更换为双引号括起来。
A double-quoted string preceded by a dollar sign ($) will cause the string to be translated according to the current locale. If the current locale is C or POSIX, the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted.
这篇关于击回声字符串以外的字符$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!