1 | #! /bin/sh
|
---|
2 | # Test for POSIX options for grep:
|
---|
3 | # grep -E -f pattern_file file
|
---|
4 | # grep -F -f pattern_file file
|
---|
5 | # grep -G -f pattern_file file
|
---|
6 | #
|
---|
7 | # Copyright (C) 2001, 2006, 2009-2021 Free Software Foundation, Inc.
|
---|
8 | #
|
---|
9 | # Copying and distribution of this file, with or without modification,
|
---|
10 | # are permitted in any medium without royalty provided the copyright
|
---|
11 | # notice and this notice are preserved.
|
---|
12 |
|
---|
13 | . "${srcdir=.}/init.sh"; path_prepend_ ../src
|
---|
14 |
|
---|
15 | fail=0
|
---|
16 |
|
---|
17 | cat <<EOF >patfile
|
---|
18 | radar
|
---|
19 | MILES
|
---|
20 | GNU
|
---|
21 | EOF
|
---|
22 |
|
---|
23 | # match
|
---|
24 | echo "miles" | grep -i -E -f patfile > /dev/null 2>&1
|
---|
25 | if test $? -ne 0 ; then
|
---|
26 | echo "File_pattern: Wrong status code, test \#1 failed"
|
---|
27 | fail=1
|
---|
28 | fi
|
---|
29 |
|
---|
30 | # match
|
---|
31 | echo "GNU" | grep -G -f patfile > /dev/null 2>&1
|
---|
32 | if test $? -ne 0 ; then
|
---|
33 | echo "File_pattern: Wrong status code, test \#2 failed"
|
---|
34 | fail=1
|
---|
35 | fi
|
---|
36 |
|
---|
37 | # checking for no match
|
---|
38 | echo "ridar" | grep -F -f patfile > /dev/null 2>&1
|
---|
39 | if test $? -ne 1 ; then
|
---|
40 | echo "File_pattern: Wrong status code, test \#3 failed"
|
---|
41 | fail=1
|
---|
42 | fi
|
---|
43 |
|
---|
44 | cat <<EOF >patfile
|
---|
45 |
|
---|
46 | EOF
|
---|
47 | # empty pattern : every match
|
---|
48 | echo "abbcd" | grep -F -f patfile > /dev/null 2>&1
|
---|
49 | if test $? -ne 0 ; then
|
---|
50 | echo "File_pattern: Wrong status code, test \#4 failed"
|
---|
51 | fail=1
|
---|
52 | fi
|
---|
53 |
|
---|
54 | cp /dev/null patfile
|
---|
55 |
|
---|
56 | # null pattern : no match
|
---|
57 | echo "abbcd" | grep -F -f patfile > /dev/null 2>&1
|
---|
58 | if test $? -ne 1 ; then
|
---|
59 | echo "File_pattern: Wrong status code, test \#5 failed"
|
---|
60 | fail=1
|
---|
61 | fi
|
---|
62 |
|
---|
63 | Exit $fail
|
---|