Hacker News new | ask | show | jobs
by thepawn1 1346 days ago
alias fgrep='grep -F'
1 comments

the issue is that programs rely on the existence of fgrep in its PATH. your shell alias doesn't fix that.
It is a bit hacky but you could put "grep -F" in a script file in your path.

    #!/bin/sh
    exec grep -E "$@"
Of course it can be solved; no one claimed you can't. The choice here is:

- Thousands of users have to update their scripts, habits, shell configs; or

- The GNU Grep maintainers spend essentially zero minutes "maintaining" a few lines of code to automatically use -E or -F based on argv[0].

It seems to me the second is obviously the better option.

So. Thought experiment.

Which has lower cognitive load if everyone starts doing it?

Explicitly specifying switches, or argv magic? I'd argue, the switches are. In the abscence of the symlinking, that is how the tool functionality would have to be driven anyway.

Argv magic now runs into a problem if another program sharing the name ever comes into existence on the path. It's also completely unergonomic in a sense, because short of looking at the source, you have no way of knowing what argv transforms implementations support are, and in order to use them, you must explicitly pollute the Symbol namespace with a denormalized util. Also, the argv magic does require one extra shell to do the transform from !grep to grep -!, Which is technically more overhead. On the other hand, fgrep and egrep are ironically easier to grep/sed for as opposed to grep/ -[F|E]

One tool, one manual, one name, one argv0.

I am not the Grand Poobah of the Internet, however, even if their hat is in my possession, so I understand that it is likely that the fgrep/egrep convention is probably deeply entrenched, and likely to spawn a new holy war on par with Emacs/Vim. Tabs/spaces, etc...

I don't think grep does any argv-stuff; I took a quick look and I don't see it.

As far as I can tell this is the entire maintenance burden:

  $ cat =egrep =fgrep
  #!/bin/sh
  exec grep -E "$@"
  #!/bin/sh
  exec grep -F "$@"
what shell does this?

    # unalias grep && unalias egrep && cp "$(command -v grep)" "$(dirname "$(command -v grep)")/egrep"
1 line. Fixed. Done. Btw needs to be run as root ( as signified by # prompt above)

EDIT: see other comment in this thread from FreeBSD user that on FreeBSD grep, egrep, and fgrep are all separate but identical (copies) of the same file. So this isn’t quite such a silly solution as some might think.

The current contents (not joking): (this is why the situation is crazy)

  #!/bin/sh
  cmd=${0##\*/}
  echo "$cmd: warning: $cmd is obsolescent; using grep -E" >&2
  exec grep -E "$@"
I cannot edit anymore, so I add this:

This is the case in a distribution (Arch) that has effectively taken the maintainer's advice into account, not the reverse.