本文介绍了shell脚本中使用grep的图案文字(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想评价一个shell脚本在的grep
前pression,而grep所使用的文字星号(*),但看来,星号由我的bash扩展剩下的文字星号代替:
I'm trying to evaluate a grep
expression inside of a shell script, and that grep uses a literal asterisk (*), but that asterisk appears to be expanded by my bash instead of remaining a literal asterisk:
branch_description=$(git branch --list -vv | grep "^\*")
我能做些什么来运行的grep
在这种情况下,让它收到的文字星号在其 PATTERN
参数?
What can I do to run grep
in this context and let it receive a literal asterisk in its PATTERN
argument?
推荐答案
的问题是,是bash间preting的 \\
和剥离出去了,因为它是内双引号。更改为
The problem is that bash is interpreting the \
and stripping it away, because it's inside double quotes. Changing to
branch_description=$(git branch --list -vv | grep '^\*')
会做你想要什么。看到在bash的手册引述部分。
will do what you want. See the section on QUOTING in the bash manual.
这篇关于shell脚本中使用grep的图案文字(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!