本文介绍了grep模式单引号和双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

grep 模式包含在单引号和双引号之间是否有区别?

Is there any difference between enclosing grep patterns in single and double quotes?

grep "abc" file.txt

grep 'abc' file.txt

我要问的是,因为我无法独自测试所有可能的情况,而且我不想偶然发现我弄错了的情况:)

I'm asking since there's no way I could test all possible cases on my own, and I don't want to stumble into a case that I get wrong :)

推荐答案

如果您有特殊字符,我会发现有所不同:

I see a difference if you have special characters :

Ex:

grep "foo$barbase" file.txt

shell会尝试扩展变量 $ barbase ,这可能不是您想要的.

The shell will try to expand the variable $barbase, this is maybe not what you intended to do.

相反,您键入

grep 'foo$barbase' file.txt

$ bar 是按字面意思.

最后,默认情况下始终首选单引号,这样会更强.

Finally, always prefer single quotes by default, it's stronger.

这篇关于grep模式单引号和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:25