Fgrep or grep -F, which one is better for a portable script?

I have this controversial comment on this answer to the question, should we use fgrep orusing a switch -F

(i.e. grep -F

) for portability. Points that have been highlighted so far:

grep -F

:

  • It is a POSIX standard.
  • GNU grep

    declared fgrep

    obsolete.

fgrep

:

  • Historically, this was before the option grep -F

    .
  • Even though GNU grep has been declared fgrep

    deprecated, they seem to stick with it for its historical use.

If you consider old (really old) systems, then you can probably find some that don't have them grep -F

(and I think the chances of this happening are very rare). But do we really need to worry about these very old machines and avoid the POSIX standard?

If you think about the current situation and turn on those old machines (which supposedly / supposedly don't have grep -F

) then there will be more systems that support fgrep

.

On the other hand, if you look to the future, it fgrep

will become history, and grep -F

obsess it as a POSIX standard.

And besides, isn't it a common practice to use the POSIX standard now for better portability?

+1


source to share


1 answer


This question is a bit mostly opinion based. Even then, I would like to put my two cents here: -

As you mentioned, fgrep

will be history and also grep -F

is POSIX standard, then resolution is fine (to keep legacy codes alive); using fgrep is absolutely absurd in my opinion.

These users can be easily persuaded to download the new version of GNU grep from the official page of the GNU Grep project.As on my system, the grep version is 2.20 (Linux is CentOS 7, kernel is 3.10).



So, I would give two reasons: -

  • For some purposes, newer versions of the software are released - to improve from the previous version and remove any bugs, etc. So here GNU Grep already recommends using grep -F

    which is the POSIX standard.

  • And downloading and installing a new version of the software is not a difficult task. it doesn't require any additional library or anything as a dependency, just a better version that does all kinds of searches, which removes the responsibility of using it more fgrep

    .

Using old ideas to preserve legacy codes would be disgusting, but again, for future uses one should stick to the POSIX standard and always use grep -F

.

+3


source







All Articles