grep命令,值包含空格
我有一个文件mail.txt,其中包含以下内容:
John Doe [email protected]
Mary Doe [email protected]
如果我在控制台中键入命令:
grep -ia 'John Doe' mail.txt
我会收到结果,但是如果我想在脚本中写下它,例如:
var="'John Doe'"
mail=mail.txt
result="`grep -ia $var $mail`"
我收到错误:grep:grep:grep: doe':没有这样的文件或目录
。如何解决?
I have a file mail.txt with the following contents:
John Doe [email protected]
Mary Doe [email protected]
if I type the command in the console :
grep -ia 'John Doe' mail.txt
I receive a result, but if I want to write it in a script, for example:
var="'John Doe'"
mail=mail.txt
result="`grep -ia $var $mail`"
I receive the error: grep: Doe': No such file or directory
. How can this be solved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要使用双引号即可分配变量。
因此,在定义命令时,您可以再次使用双引号。
看起来像这样:
或
You just need to use double quotes to assign the variable.
So you can use double quotes again when defining the command.
could look like this:
or