本文介绍了如何将grep输出重定向到变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些烟斗.例如,我有这个管道:
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]+")或
month=$(date +%B)更多推荐
如何将grep输出重定向到变量?
发布评论