2011年9月6日 星期二

Linux script: grep in a test/if statement

http://www.unix.com/shell-programming-scripting/57761-using-grep-test-if-statement.html
exampe1:

cd ${PATH}

if [ 'grep SOME_STRING $PATH/$LOGFILE' ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi
exit 1


Example 2:
cd ${PATH}

if [ $(grep -c SOME_STRING $PATH/$LOGFILE) -ne 0 ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi

exit 0

Exampe 3:
cd ${PATH}

grep -q SOME_STRING $PATH/$LOGFILE
if [ $? -eq 0 ]
then
rm ${FILE}
./anotherScript
else
exit 1
fi

exit 0

沒有留言:

張貼留言