Skip to content

Commit 43bcc71

Browse files
committed
refactor: use grep -E/-F instead of fgrep/egrep
1 parent 1de00d1 commit 43bcc71

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/etc/cat-and-grep.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Options:
2626
-i Case insensitive search.
2727
'
2828

29-
GREPPER=fgrep
29+
GREPPER=grep
3030
INVERT=0
3131
GREPFLAGS='q'
3232
while getopts ':vieh' OPTION; do
@@ -39,7 +39,7 @@ while getopts ':vieh' OPTION; do
3939
GREPFLAGS="i$GREPFLAGS"
4040
;;
4141
e)
42-
GREPPER=egrep
42+
GREPFLAGS="E$GREPFLAGS"
4343
;;
4444
h)
4545
echo "$USAGE"
@@ -51,6 +51,15 @@ while getopts ':vieh' OPTION; do
5151
esac
5252
done
5353

54+
# an utility function to check if a string contains a substring
55+
stringContain() { [ -z "$1" ] || { [ -z "${2##*$1*}" ] && [ -n "$2" ];};}
56+
57+
if ! stringContain 'E' "$GREPFLAGS"
58+
then
59+
# use F flag if there is not an E flag
60+
GREPFLAGS="F$GREPFLAGS"
61+
fi
62+
5463
shift $((OPTIND - 1))
5564

5665
# use gnu version of tool if available (for bsd)

0 commit comments

Comments
 (0)