6 ms·
(Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8
- MobiusHorizons 4y agoI feel like this is a pretty silly thing to deprecate. What is the harm in keeping around egrep and fgrep?
- Forge36 4y agoOn their own it's probably trivial. I suspect over time it becomes a large tasks/maintenance question. Depending on the number of additional commands on similar removal paths it may have performance/memory improvement implications for minimum supported specs.
- Spivak 4y agoDoes it though? I mean we’re really talking about a teeny tiny little startup code to read arg0 and use it to do the equivalent of passing -E or -P.
- LukeShu 4y agoEven simpler than that! GNU grep hasn't done arg0-inspection since 2002; since then `fgrep` and `egrep` have been short[1] shell scripts. [1]: 11 lines at the longest, 2 lines at the shortest; currently 4 lines https://git.savannah.gnu.org/cgit/grep.git/tree/src/egrep.sh?h=v3.8 https://git.savannah.gnu.org/cgit/grep.git/tree/src/egrep.sh...
- DaSHacka 4y agoI don't think that's why, on my Arch Linux box they're just shell scripts that pass the -E/-F argument to regular Grep. $ cat /usr/bin/egrep #!/bin/sh exec grep -E "$@" $ cat /usr/bin/fgrep #!/bin/sh exec grep -F "$@"
- somat 4y agointeresting, on openbsd they are the same inode and it uses it uses arg0 to figure out what to do. ls -li /usr/bin/grep /usr/bin/egrep /usr/bin/fgrep 285407 -r-xr-xr-x 6 root bin 31896 Aug 14 15:23 /usr/bin/egrep 285407 -r-xr-xr-x 6 root bin 31896 Aug 14 15:23 /usr/bin/fgrep 285407 -r-xr-xr-x 6 root bin 31896 Aug 14 15:23 /usr/bin/grep
- LukeShu 4y agoGNU has flip-flopped on it. - Based on the NEWS file, it sounds like pre-v2.0 (1993) versions had totally separate implementations for each program and didn't have -E, -F, or -G flags (but only history back to 1998 has been imported to Git, and I don't feel like digging up old tarballs to verify) - In the first revision checked in to Git (1998), it's argv[0]-inspecting, but the program is compiled identically 3 times, rather than being hardlinked or symlinked. https://git.savannah.gnu.org/cgit/grep.git/commit/?id=06b9f7e683e7650804cadd9a4c5cf6bff6c89625 https://git.savannah.gnu.org/cgit/grep.git/commit/?id=06b9f7... - In v2.2c (1998) it changed to be 3 separate binaries https://git.savannah.gnu.org/cgit/grep.git/commit/?id=f7620959fee786f7b8edde63bd61d6a3e56daec4 https://git.savannah.gnu.org/cgit/grep.git/commit/?id=f76209... - In v2.5 (2002) it changed to be argv[0]-inspecting hardlinks https://git.savannah.gnu.org/cgit/grep.git/commit/?id=f620c907368af50cc920699897bd88878591d011 https://git.savannah.gnu.org/cgit/grep.git/commit/?id=f620c9... - In v2.5.1 (2002) it changed to be shell scripts https://git.savannah.gnu.org/cgit/grep.git/commit/?id=5cb71b0d603501ec10bcc3df3261bd8a760cda84 https://git.savannah.gnu.org/cgit/grep.git/commit/?id=5cb71b... <---- (this is a spicy commit message) - In v2.5.2 (2005) it changed to be 3 separate binaries (the `fgrep` binary being a lot smaller than the `grep` binary) https://git.savannah.gnu.org/cgit/grep.git/commit/?id=d25bebd35aae9c5ed0e1d62eb211ff16586e759f https://git.savannah.gnu.org/cgit/grep.git/commit/?id=d25beb... - In v2.19 (2014) it changed back to shell scripts https://git.savannah.gnu.org/cgit/grep.git/commit/?id=b639643840ef506594b6c46e5b24d9980a33e78e https://git.savannah.gnu.org/cgit/grep.git/commit/?id=b63964...
- lolc 4y ago
- augusto-moura 4y agoWhy should GNU maintain 3 different command profiles on their own? If is really necessary or useful distros can easily shim them to a grep wrapper if they want to
- chasil 4y agoI'm shocked - neither egrep nor fgrep are POSIX standards! I had every expectation that they would be. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/g... https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ https://pubs.opengroup.org/onlinepubs/9699919799/utilities/
- Forge36 4y agoWhat's the rational for keeping them around in new installs? How have others handled command deprecation on the past? May this also serve as a warning about adding functionality and being very careful about removing it.
- lolc 4y agoI have numerous scripts in production that rely on fgrep. Not sure about egrep. So I'm happy there's a warning before these commands are eventually removed.
- dooglius 4y agoWhat does "$@@" do? I have used just "$@" for what the script at the end is trying to accomplish, is there some edge case where that fails?
- ncmncm 4y agoThe main addendum is that fgrep without a file list is -F, and egrep is -E.
- williadc 4y agoAn alias also seems like it'd work. alias egrep='grep -E' alias fgrep='grep -F'
- chasil 4y agoPOSIX requires that aliases be observed in the context of a shell script, but there is a trap here. When bash is called as /bin/sh, it will be in POSIX mode, and will honor those aliases. When called as anything else or when otherwise not in POSIX mode, those aliases will fail. Bash was around for a decade before the POSIX shell standard was defined, so there is legacy baggage.