1

I am having this controversial commentary on this answer to a question 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.

fgrep:

  • Historically it came before the grep -F option.
  • Even though GNU grep declared fgrep to be deprecated, they seem to stick with it for its 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 don't have grep -F), then there will be more systems supporting fgrep.

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

And moreover isn't it a generally accepted practice now to use the POSIX standard for better portability?

Community
  • 1
  • 1
Jahid
  • 21,542
  • 10
  • 90
  • 108
  • 2
    Dare I say that 99.999% of the questioners asked on SO don't care about portability. They just want some command/tool that does a little text processing. By all means, it's well & good to note about the possible portability issues in answers but projecting it as if it's going "break" a lot of code is a fallacy. A lot of "portability" these days in shell scripts solely serves to boost the egos of some people who love to say "but it won't work in the bourne shell of 1977". – P.P Jul 18 '15 at 11:53
  • 2
    @Jahid Who the heck cares, they are the same for all intents and purposes, have been that way for 30+ years, and are likely to stay the same for at least as long. Not even the GNU manual claims there's any difference, you're the only one putting up a show about it. – lcd047 Jul 18 '15 at 12:39
  • @lcd047 I agree with [shekhar suman](http://stackoverflow.com/a/31490786/3744681) , Using `fgrep` now a days is totally absurd. It makes no sense to recommend using `fgrep` unless someone is already using it. – Jahid Jul 18 '15 at 15:42
  • 2
    @Jahid According to [POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html), `-w` and `-o` are not standard options for `grep`. Would you consider their use equally absurd? Just out of curiosity. – lcd047 Jul 18 '15 at 17:18
  • 1
    @lcd047 that is entirely a different topic, we are talking about an option and it's non-POSIX alternative, while those options (`-w` and `-o`) don't have a POSIX alternative to begin with. If you need to use them you will have to use them as is and take portability risk deliberately, that is **not** illogical. – Jahid Jul 19 '15 at 03:54
  • 1
    For what it's worth: I [asked](http://lists.gnu.org/archive/html/bug-grep/2015-07/msg00034.html) about the future of `fgrep` on GNU grep's list `bug-grep`, and got an [answer](http://lists.gnu.org/archive/html/bug-grep/2015-07/msg00035.html) from one of the developers. – lcd047 Jul 20 '15 at 04:58

1 Answers1

3

This question is a bit primarily opinion based. Even then I'd like to put my two cents here :-

As you mentioned that fgrep is going to be a history and also grep -F is a POSIX standard, then permitting is OK(for preserving legacy codes); using fgrep in my view is totally absurd.

Those users can be easily persuaded to download a new version of GNU grep from the official GNU Grep project page. Like in my system the version of grep is 2.20(Linux - CentOS 7; kernel - 3.10).

So, I'd present 2 reasons :-

  1. Newer software versions are released for some purpose --- to improve from the previous version and remove any kind of bugs,etc. So, here GNU Grep already recommends to use grep -F which is a POSIX standard.

  2. And, downloading and installing a new version of software is not a much complex task. it doesn't require any extra new library or something as a dependency, just a better version which does all kinds of search, which removes liability of using fgrep anymore.

Sticking with older ideas just to preserve legacy codes would be a point against it, but, then again for future usages one should stick to POSIX standard and always use grep -F.

Am_I_Helpful
  • 18,735
  • 7
  • 49
  • 73