如何将此命令的输出分配给Shell中的变量?

时间:2014-04-30 18:54:24

标签: linux bash shell

我有以下命令:

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

1 个答案:

答案 0 :(得分:2)

POM_ERRORS=$(egrep -e "\\\\" pom.xml | egrep -v -e "\\\\$")