如何grep的输出重定向到一个变量? [英] How to redirect grep output to a variable?
本文介绍了如何grep的输出重定向到一个变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些管道。例如,我有这个管道:
用户名@用户:〜$ CAL |头-1 | grep的-OP[A-ZA-Z] +
有关这个管道,我得到这个结果:
九月
我想这个结果存储到一个变量。我写了下面的命令:
用户名@用户:〜$ CAL |头-1 |月= $(grep的-OP[A-ZA-Z] +)|回声$一个月
和我得到空字符串。有什么问题?
解决方案
月= $(CAL |头-1 | grep的-OP[A-ZA-Z] +)
或
月= $(日期+%B)
I have some pipe. For example, I have this pipe:
user@user:~$ cal | head -1 | grep -oP "[A-Za-z]+"
For this pipe I get this result:
September
I want to store this result to a variable. I write the following commands:
user@user:~$ cal | head -1 | month=$(grep -oP "[A-Za-z]+") | echo $month
And I get the blank string. What is the problem?
解决方案
month=$(cal | head -1 | grep -oP "[A-Za-z]+")
or
month=$(date +%B)
这篇关于如何grep的输出重定向到一个变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文