if语句中的2 grep

时间:2012-11-27 21:05:39

标签: bash shell unix

任何人都可以告诉我这将是什么问题?我知道这是一个半秒的问题,但请帮助:) egrep "first" a.sh && egrep "second" a.sh工作,a.sh包含第一,第二,第三等... Thx!

 if [[ egrep "first" a.sh && egrep "second" a.sh ]]; then
 echo "success"
 fi

2 个答案:

答案 0 :(得分:8)

您的问题是您正在使用[[命令。只使用greps。

if egrep ... && egrep ... ; then

答案 1 :(得分:1)

我认为这可能是你想要做的事情:

found_1=$(egrep "first" a.sh)
found_2=$(egrep "second" a.sh)

if [[ -n "$found_1" ]] && [[ -n "$found_2" ]]; then
    echo "success"
fi