问题
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?
回答1:
month=$(cal | head -1 | grep -oP "[A-Za-z]+")
or
month=$(date +%B)
来源:https://stackoverflow.com/questions/25710640/how-to-redirect-grep-output-to-a-variable