diff options
| author | kxxt <rsworktech@outlook.com> | 2022-09-21 20:51:03 +0800 |
|---|---|---|
| committer | kxxt <rsworktech@outlook.com> | 2022-09-22 08:47:41 +0800 |
| commit | 43bcc71d074a10d9186e27f9bf21b9dafa815bf5 (patch) | |
| tree | a96f064a499986b73ead8ce9144c573f8ba3beaf | |
| parent | 1de00d1ac5247a02184ef7ad044f6521ade7e0cc (diff) | |
| download | rust-43bcc71d074a10d9186e27f9bf21b9dafa815bf5.tar.gz rust-43bcc71d074a10d9186e27f9bf21b9dafa815bf5.zip | |
refactor: use grep -E/-F instead of fgrep/egrep
| -rwxr-xr-x | src/etc/cat-and-grep.sh | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/etc/cat-and-grep.sh b/src/etc/cat-and-grep.sh index 77dc52a9350..08de25a7778 100755 --- a/src/etc/cat-and-grep.sh +++ b/src/etc/cat-and-grep.sh @@ -26,7 +26,7 @@ Options: -i Case insensitive search. ' -GREPPER=fgrep +GREPPER=grep INVERT=0 GREPFLAGS='q' while getopts ':vieh' OPTION; do @@ -39,7 +39,7 @@ while getopts ':vieh' OPTION; do GREPFLAGS="i$GREPFLAGS" ;; e) - GREPPER=egrep + GREPFLAGS="E$GREPFLAGS" ;; h) echo "$USAGE" @@ -51,6 +51,15 @@ while getopts ':vieh' OPTION; do esac done +# an utility function to check if a string contains a substring +stringContain() { [ -z "$1" ] || { [ -z "${2##*$1*}" ] && [ -n "$2" ];};} + +if ! stringContain 'E' "$GREPFLAGS" +then + # use F flag if there is not an E flag + GREPFLAGS="F$GREPFLAGS" +fi + shift $((OPTIND - 1)) # use gnu version of tool if available (for bsd) |
