1#!/bin/sh 2# Test for status code for GNU grep. 3# status code 4# 0 match found 5# 1 no match 6# 2 file not found 7 8: ${srcdir=.} 9 10failures=0 11 12# should return 0 found a match 13echo "abcd" | ${GREP} -E -e 'abc' > /dev/null 2>&1 14if test $? -ne 0 ; then 15 echo "Status: Wrong status code, test \#1 failed" 16 failures=1 17fi 18 19# should return 1 found no match 20echo "abcd" | ${GREP} -E -e 'zbc' > /dev/null 2>&1 21if test $? -ne 1 ; then 22 echo "Status: Wrong status code, test \#2 failed" 23 failures=1 24fi 25 26# the filename MMMMMMMM.MMM should not exist hopefully 27if test -r MMMMMMMM.MMM; then 28 echo "Please remove MMMMMMMM.MMM to run check" 29else 30 # should return 2 file not found 31 ${GREP} -E -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1 32 if test $? -ne 2 ; then 33 echo "Status: Wrong status code, test \#3 failed" 34 failures=1 35 fi 36 37 # should return 2 file not found 38 ${GREP} -E -s -e 'abc' MMMMMMMM.MMM > /dev/null 2>&1 39 if test $? -ne 2 ; then 40 echo "Status: Wrong status code, test \#4 failed" 41 failures=1 42 fi 43 44 # should return 0 found a match 45 echo "abcd" | ${GREP} -E -q -s 'abc' MMMMMMMM.MMM - > /dev/null 2>&1 46 if test $? -ne 0 ; then 47 echo "Status: Wrong status code, test \#5 failed" 48 failures=1 49 fi 50fi 51 52exit $failures 53