如何grep表示美元符号($)?
% cat temp$$$ hello1
$$  hello2
    hello3
##  hello4
    hello5 $$$
% cat temp | grep "$$$"
Illegal variable name.
% cat temp | grep "\$\$\$"
Variable name must contain alphanumeric characters.
%
我想要grep $$$,我希望结果是
% cat temp | grep <what should go here?>$$$ hello1
    hello5 $$$
%
为了区分,我将提示标记为%。
- 这里有什么问题?
 - 应该采取什么 是什么?
 
回答:
问题在于外壳程序在双引号字符串内扩展了变量名。因此,"$$$"它尝试读取以first开头的变量名$。
另一方面,单引号中的变量不会扩展。因此,如果不是因为在正则表达式中表示行尾的特殊字符这一事实,那'$$$'将是
可行的$。因此需要进行转义:'\$\$\$'。
以上是 如何grep表示美元符号($)? 的全部内容, 来源链接: utcz.com/qa/424333.html

