From 92e9596050def34d784f8c837339b4bebab40fd3 Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 1 Feb 2017 21:17:55 +0000 Subject: [PATCH] searchsploit: use --color only when grep supports it this fixes usage with busybox grep. --- searchsploit | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/searchsploit b/searchsploit index 45a66ca8a..8af805c06 100755 --- a/searchsploit +++ b/searchsploit @@ -42,7 +42,14 @@ SEARCH="" CASE_TAG_GREP="-i" CASE_TAG_FGREP="tolower" AWK_SEARCH="" +COLOUR_OFF_GREP= +COLOUR_ON_GREP= +## Check if our grep supports --color +if grep --help 2>&1 | grep "[-]-color" >/dev/null 2>&1 ; then + COLOUR_OFF_GREP="--color=never" + COLOUR_ON_GREP="--color=always" +fi ## Set LANG variable to avoid illegal byte sequence errors LANG=C @@ -338,7 +345,7 @@ function buildterms() ## Search both title AND path if [[ "${FILEPATH}" -eq 1 ]]; then ## Search command for each term (with case sensitive flag, "-c") - SEARCH="${SEARCH} | grep --color=never -F ${CASE_TAG_GREP} \"${tag}\"" + SEARCH="${SEARCH} | grep ${COLOUR_OFF_GREP} -F ${CASE_TAG_GREP} \"${tag}\"" ## Search just the title, NOT the path ("-t"/"-e") else ## If there is already a value, prepend text to get ready @@ -612,7 +619,7 @@ fi ## If we are to use colour ("--colour"), add the value here if [[ "${COLOUR_TAG}" ]] && [[ "${JSON}" -eq 0 ]]; then - COLOUR_TAG="grep --color=always -iE \"${COLOUR_TAG}|$\"" + COLOUR_TAG="grep ${COLOUR_ON_GREP} -iE \"${COLOUR_TAG}|$\"" fi