fgrep或grep -F,哪一个更适合便携式脚本? [英] fgrep or grep -F, which one is better for portable script?

查看:157
本文介绍了fgrep或grep -F,哪一个更适合便携式脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个回答有这个有争议的评论,是否应该使用 fgrep -F 开关(即)显示标记为'grep'rel =tag> grep 的问题。 grep -F )的可移植性。到目前为止发现的几点是:
$ b

grep -F




  • 是POSIX标准版。
  • GNU grep code> fgrep 将被弃用。


fgrep


  • 历史上,它出现在 grep -F 选项之前。

  • 即使宣称 fgrep 的GNU grep被弃用,它们似乎也会坚持使用它。




  • 如果你考虑过旧的系统,那么你可能会发现其中一些没有 grep -F code>(我认为它发生的机会非常罕见)。但是我们是否真的需要担心那些非常旧的机器,并且为此避免使用POSIX标准!!



    如果您考虑当前的情况并包括那些旧机器据称/没有 grep -F ),那么会有更多系统支持 fgrep



    另一方面,如果你展望未来, fgrep 将成为历史,而 grep -F 将作为POSIX标准取胜。



    此外,现在使用POSIX标准的更好的可移植性?

    解决方案

    这个问题有点基于意见。即便如此,我想把我的两分钱放在这里: -



    正如你所提到的, fgrep 将会是一个历史记录,同时也是 grep -F 是POSIX标准,那么允许是OK(用于保留遗留代码)。在我看来,使用fgrep是完全荒谬的。



    这些用户可以通过 轻松说服 来自官方GNU Grep项目页面的GNU grep。在我的系统中,grep的版本是2.20(Linux - CentOS 7; kernel - 3.10)。

    因此,我会提出两个原因: -


    1. 为了某种目的发布了更新的软件版本---以改进以前的版本并删除任何类型的错误等。所以,这里GNU Grep已经建议使用 grep -F 这是一个POSIX标准。

    2. ,下载并安装新版本的软件并不是一项复杂的任务。它不需要任何额外的新库或其他东西作为依赖,只是一个更好的版本,它可以进行各种搜索,从而消除了使用 fgrep >


      保留旧代码仅仅是为了保留遗留代码会违反它,但是,再次为了将来的用法,应该坚持POSIX标准,并且总是使用 grep -F

      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?

      解决方案

      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.

      这篇关于fgrep或grep -F,哪一个更适合便携式脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆