原因:在意外令牌“fi”附近出现Bash语法错误

时间:2015-03-27 13:34:22

标签: bash if-statement grep mailx

所以我得到的错误是在意外令牌'fi'附近的语法错误。在第二个' fi'。对此我一直在挠头。任何帮助是极大的赞赏!谢谢!

#!/bin/bash  

TFILE=/tmp/scripts/pdsh_demo.tmp  
if [ -f $TFILE ]; then  
   rm $TFILE  
fi  
/usr/bin/pdsh -R ssh -w host[0001-0200] 'command | grep -v "something"' >> $TFILE    

if [ ! -s $TFILE ]; then  
    exit  
fi  
if [ -f $TFILE ]; then  
    if grep -q "something" $TFILE ; then  
        grep -i "something" $TFILE | mailx -r "test.server" -s "Critical: something" -a $TFILE "test@test.com"  
    fi   
fi

1 个答案:

答案 0 :(得分:-3)

in

if grep -q "something" $TFILE ; then 

应该是

if [ $(grep -q "something" $TFILE) ]; then