如何将grep输出重定向到变量? [英] How to redirect grep output to a variable?

查看:27
本文介绍了如何将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输出重定向到变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆