如果我使用该hub
命令在 GitHub 上创建拉取请求并收到错误消息,则会在四行中输出:
hub pull-request -p -b MyOrg:main -h Test_Branch -m "testing"
输出:
Everything up-to-date
Branch 'Test_Branch' set up to track remote branch 'Test_Branch' from 'MyOrg'.
Error creating pull request: Unprocessable Entity (HTTP 422)
A pull request already exists for MyOrg:Test_Branch.
现在,如果我尝试以这种方式存储输出:
output=$(hub pull-request -p -b MyOrg:main -h Test_Branch -m "testing")
然后奇怪的是只有第二行存储在output
.
如果我打印它,我只会看到第二行:
echo $output
结果:
Branch 'Test_Branch' set up to track remote branch 'Test_Branch' from 'MyOrg'.
我的总体目标是捕获输出而不是将其打印给用户。我只想向他们展示一条简单的错误消息(而不是四行输出)。理想情况下,我只想grep
在Error creating pull request
此基础上打印专门的错误消息。
谁能告诉我该怎么做?谢谢。