GNU bug report logs -
#36764
grep -q throwing up No such file or directory error
Previous Next
Reported by: Lewis Farnworth <lewfar99 <at> gmail.com>
Date: Mon, 22 Jul 2019 17:54:02 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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
This bug report was last modified 5 years and 299 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.