Skip to content
Browse files

portable grep -q

  • Loading branch information...
1 parent 23cbb38 commit d144e08c095bc87515c71df54ffd85d6edb6d1e3 @jneen committed Aug 1, 2011
Showing with 21 additions and 1 deletion.
  1. +21 −1 lib/util.sh
View
22 lib/util.sh
@@ -11,7 +11,27 @@ exists() {
type "$@" >/dev/null 2>/dev/null
}
-alias matches='grep -q'
+test_grepq() {
+ local output="$(echo x | grep -q x)"
+ [[ $? == 0 ]] || return 1
+ [[ -z "$output" ]] || return 1
+ return 0
+}
+
+test_greps() {
+ local output="$(echo x | grep -s x)"
+ [[ $? == 0 ]] || return 1
+ [[ -z "$output" ]] || return 1
+ return 0
+}
+
+if test_grepq; then
+ matches() { grep -q "$@" ;}
+elif test_greps; then
+ matches() { grep -s "$@" ;}
+else
+ matches() { grep "$@" 2>&1 >/dev/null ;}
+fi
pluralize() {
if [ -n "$1" ]; then

0 comments on commit d144e08

Please sign in to comment.
Something went wrong with that request. Please try again.