bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#36764: grep -q throwing up No such file or directory error


From: Stephane Chazelas
Subject: bug#36764: grep -q throwing up No such file or directory error
Date: Wed, 24 Jul 2019 07:36:32 +0100
User-agent: NeoMutt/20171215

2019-07-22 16:16:43 -0600, Assaf Gordon:
[...]
> or the more robust:
> 
>    printf "%s" "$variable_i'm_looking_in" | grep -q "$thing_i'm_looking_for"
[...]

Preferably (POSIXly):

printf "%s\n" "$variable_i'm_looking_in" | grep -qe "$thing_i'm_looking_for"

Or

printf "%s\n" "$variable_i'm_looking_in" | grep -q -- "$thing_i'm_looking_for"

That is add a newline character so grep's input is valid text
and guard against "$thing_i'm_looking_for" starting with -.

[...]
> Use something like:
> 
>   if echo "$mailServ" | grep -q "google.com"; then
>      printf "%s uses google for mail \n" $mailServ
>   fi
[...]

Note that it matches on googleXcom as well as "." is a regexp
operator (I see you made that note later one). Use grep -q
'google\.com' or grep -Fq google.com, but better here would be
to use a case statement and drop grep altogether:

case $mailServ in
  (*google.com*)
    printf '%s uses google for mail\n' "$mailServ"
esac

-- 
Stephane





reply via email to

[Prev in Thread] Current Thread [Next in Thread]