I am having this controversial commentary on this answer to a quesion whether we should use or with the -F switch (i.e grep -F) for portability. The points that have been came into light so far are:

grep -F:

  • Is a POSIX Standard.
  • GNU grep has declared fgrep to be deprecated.


  • Historically it came before the grep -F option.
  • Even though GNU grep declared fgrep to be deprecated, they seem to stick with it for it's historical use.

If you consider old (really old) systems, then probably you can find some of them not having the grep -F in them (and I think the chance of it happening is very rare). But do we really need to worry about those very very old machines and avoid POSIX standard for that!!

If you think about the current situation and include those old machines (which supposedly/allegedly doesn't have grep -F), then the systems supporting fgrep will be more.

On the other hand, if you look into the future, fgrep is going to be a history and grep -F will triumph upon it as a POXIS standard.

And moreover isn't it a general knowledge now, to use POSIX standard for better portability?

  • Same question on Stackoverflow: stackoverflow.com/questions/31490686/… . Please do not cross post.
    – Celada
    Jul 18, 2015 at 12:22
  • @Celada that post is going to be closed soon, it's kinda off-fopic there.
    – Jahid
    Jul 18, 2015 at 12:23
  • 3
    In that case, please delete it and don't create extra work for everybody.
    – terdon
    Jul 18, 2015 at 12:42

1 Answer 1


grep -F is POSIX. fgrep is not. Use grep -F and make it clear that your script depends on a POSIX grep. Clearly stated dependencies are all you need.

I guess you could use both...

if    command -v fgrep 
then  _grepf(){ fgrep "$@"; }
else  _grepf(){ grep -F "$@"; }
fi    >/dev/null

...but doing stuff like that is hacky and usually a waste of time. Set a minimum-level of conformance in your dependency list and allow the standard to handle the rest.

Not the answer you're looking for? Browse other questions tagged .