【问题标题】:How can I assign the output of this command to a variable in Shell?如何将此命令的输出分配给 Shell 中的变量?
【发布时间】:2014-04-30 18:54:23
【问题描述】:

我有以下命令:

egrep -e "\\\\" pom.xml | egrep -v -e "\\\\$"

我想将它分配给一个变量,以便稍后在这段代码中回显它:

egrep -e "\\\\" pom.xml | egrep -v -e "\\\\$"  &> /dev/null
if [ $? == 0 ]; then
   echo "Errors in POM were found"
   echo "line matches (result of the command)"
fi

【问题讨论】:

  • 请注意,根据您的 shell 及其版本,管道的返回值可能是第一个命令或最后一个命令。您可能只需在第一个 grep 中的模式末尾添加一个句点并获得相同的结果。
  • 我会考虑的,谢谢!

标签: linux bash shell


【解决方案1】:
POM_ERRORS=$(egrep -e "\\\\" pom.xml | egrep -v -e "\\\\$")

【讨论】:

    猜你喜欢
    • 2017-07-21
    • 2012-01-27
    • 2016-09-08
    • 1970-01-01
    • 2011-01-28
    • 2021-03-18
    • 1970-01-01
    • 2018-03-12
    • 2011-08-13
    相关资源
    最近更新 更多