5 ms·
alias fgrep='grep -F'
by thepawn1 4y ago
alias fgrep='grep -F'
- VWWHFSfQ 4y agothe issue is that programs rely on the existence of fgrep in its PATH. your shell alias doesn't fix that.
- jonas-w 4y agoIt is a bit hacky but you could put "grep -F" in a script file in your path.
- forgotpwd16 4y agoThat's what GNU grep recommends: https://www.gnu.org/software/grep/manual/html_node/Usage.html#:~:text=what%20happened%20to%20egrep%20and%20fgrep%3F%20 https://www.gnu.org/software/grep/manual/html_node/Usage.htm...
- emptyparadise 4y ago#!/bin/sh exec grep -E "$@"
- Beltalowda 4y agoOf 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.
- koprulusector 4y ago# 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.
- salawat 4y agoSo. 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...
- Beltalowda 4y agoI 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 "$@"
- yubiox 4y agowhat shell does this?
- forgotpwd16 4y agoApparently zsh replaces =cmd with cmd's absolute path. TIL.
- Beltalowda 4y agoYes, very useful to bypass aliases if need be, quickly edit a script ("vi =my-script"), etc. I don't think bash has it; you need to use where/whence/which/command/whatever (I can never remember, why are there so many?!)
- henearkr 4y agoThe 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 "$@"
- henearkr 4y agoI 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.