Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
GNU is Not Unix

GNU Grep 3.8 Starts Issuing Warnings About Using Egrep and Fgrep (phoronix.com) 86

After 104 commits from six different people, GNU grep was released Saturday, reports Phoronix.

The biggest change? "It's now made more clear that if you are still relying on the egrep and fgrep commands, it's past due for switching to just grep with the appropriate command-line arguments." The egrep and fgrep commands have been deprecated since 2007. Beginning with GNU Grep 3.8 today, calling these commands will now issue a warning to the user that instead they should use grep -E and grep -F, respectively.

Eventually, GNU Grep will drop the egrep / fgrep commands completely but there doesn't seem to be a firm deadline yet for when that removal will happen.

From grep's updated manual: 7th Edition Unix had commands egrep and fgrep that were the counterparts of the modern 'grep -E' and 'grep -F'. Although breaking up grep into three programs was perhaps useful on the small computers of the 1970s, egrep and fgrep were not standardized by POSIX and are no longer needed. In the current GNU implementation, egrep and fgrep issue a warning and then act like their modern counterparts; eventually, they are planned to be removed entirely.

If you prefer the old names, you can use use your own substitutes, such as a shell script...

Other notable changes from the release announcement:
  • The confusing GREP_COLOR environment variable is now obsolescent. Instead of GREP_COLOR='xxx' use GREP_COLORS='mt=xxx'
  • Regular expressions with stray backslashes now cause warnings

This discussion has been archived. No new comments can be posted.

GNU Grep 3.8 Starts Issuing Warnings About Using Egrep and Fgrep

Comments Filter:
  • Huh? (Score:5, Insightful)

    by Joce640k ( 829181 ) on Sunday September 04, 2022 @08:44PM (#62852361) Homepage

    Can't they just make egrep and fgrep into aliases for grep with the appropriate command line parameter added?

    ie. Not break things just because they don't like them.

    • Re: (Score:2, Insightful)

      by Anonymous Coward

      15 years isn’t enough time to fix your code?

      • Re:Huh? (Score:5, Insightful)

        by PPH ( 736903 ) on Sunday September 04, 2022 @09:13PM (#62852421)

        It's not my code.

      • Re:Huh? (Score:5, Insightful)

        by Z00L00K ( 682162 ) on Sunday September 04, 2022 @10:42PM (#62852531) Homepage Journal

        In many cases it's old scripts where the maintainer left many years ago but they work as they should.

        Don't fix it if it's not broken.

        Changes like this is what really causes bugs, not fixes them.

        Many years ago I tried grep -E instead of egrep and experienced different result. Something was different, but I don't remember now since it was probably 15 to 20 years ago.

        Another factor is that if you remove egrep/fgrep you'll end up in environment specific scripts that have to know if it's a GNU environment or another *NIX environment. At best you can get around it with conditional statements, but it will then require editing scripts with potential for new bugs.

        • Re:Huh? (Score:4, Interesting)

          by arglebargle_xiv ( 2212710 ) on Sunday September 04, 2022 @11:09PM (#62852565)

          Many years ago I tried grep -E instead of egrep and experienced different result. Something was different, but I don't remember now since it was probably 15 to 20 years ago.

          That's probably because, unless one is aliased to the other, you'd be running version 1.52 of egrep and version 17.3 of grep. It's a nasty catch-22, people used egrep because they wanted to do exotic things that grep wouldn't do and then ended up hardcoding in egrep-specific quirks that aren't replicated in grep -E.

          • ...ended up hardcoding in egrep-specific quirks that aren't replicated in grep -E.

            Well there's your problem.

            How hard can it be to add the quirks?

        • In many cases it's old scripts where the maintainer left many years ago but they work as they should. Don't fix it if it's not broken.

          It is precisely the idea that you should always replicate and ensure all past behaviours work that either prevents progress going forward or worse causes bloat. Sure we're only talking about grep here, but apply your logic to a bigger project and you'll very quickly get to the mess that is a modern bloated OS.

          If you so desperately depend on a prior version, don't upgrade. It's as simple as that. You should not expect future systems to cater to your edge case of the past with 100% backwards compatibility. Th

          • by Z00L00K ( 682162 )

            It's more than backwards compatibility.

            Not every *NIX dialect has the same implementation of grep/egrep/fgrep. I.e. they are using their own instead of the GNU version. That's just a fact, so if you on one dialect need to use "egrep" and another "grep -E" then you are causing problems. The other dialect may not be "old" per se, just a different part of the heritage tree, but you still want your software to work as good as possible on as many dialects as possible. So unless you can convince the maintainers o

            • Based on the summary where it says egrep/fgrep didn't make it into POSIX I assume that means that grep did...

              But does POSIX just say "have something that finds strings in other strings/textfiles" or does it get down to the arguments and what expected behavior should be (ie, use-case testable stuff) ?

              • This is the POSIX synopsis for grep:

                grep [-E|-F] [-c|-l|-q] [-insvx] -e pattern_list
                [-e pattern_list]... [-f pattern_file]... [file...]

                grep [-E|-F] [-c|-l|-q] [-insvx] [-e pattern_list]...
                -f pattern_file [-f pattern_file]... [file...]

                grep [-E|-F] [-c|-l|-q] [-insvx] pattern_list [file...]

                It describes what all of that means in detail.

                The GNU man page is incorrect when it says egrep and fgrep were not standardi

      • Re:Huh? (Score:4, Informative)

        by ArmoredDragon ( 3450605 ) on Sunday September 04, 2022 @11:47PM (#62852625)

        Just use ripgrep and be done with it.

        https://github.com/BurntSushi/... [github.com]

        Unlike grep, it's optimized for computers that were made within the last 20 years, so it runs a hell of a lot faster. Easily the fastest 'grep' like tool that exists. Sure, it's not POSIX compliant, but neither is Linux, and for very good reason in both cases.

        There's also fd-find for general file name searches, which works with similar assumptions, and is similarly fast:

        https://github.com/sharkdp/fd [github.com]

      • Re:Huh? (Score:4, Insightful)

        by phantomfive ( 622387 ) on Sunday September 04, 2022 @11:51PM (#62852631) Journal

        Backwards compatibility is important.

        There is no gain from removing these commands.
        By removing them anyway, the maintainers demonstrate that they don't understand the importance of backwards compatibility. Which is a problem.

      • Sometimes it is someone else's code, or someone else's explanation of the solution to a problem which you've looked up precisely because you aren't expert in the area. And some of us are busy enough that we don't necessarily want to have to change old code that has been working correctly for years.
      • My code is not broken. GNU Grep is breaking it. On purpose. Because some navel gazer thinks we should stop doing it this way. There's not actually a technical issue driving this. It's arbitrary.
      • Comment removed based on user account deletion
      • by dbrower ( 114953 )
        I can fix my code. I can't fix my fingers of ingrained habits.
    • Can't they just type 1 less letter for compatibility reasons after 15 years? I know that is a lot to ask, (less work and compliance) but even the densest of rocks can change.

      • Re:Huh? (Score:4, Funny)

        by Waccoon ( 1186667 ) on Sunday September 04, 2022 @09:07PM (#62852401)

        Hmm... spend an in significant amount of time preparing a legacy hack using an alias, or ask thousands of people to waste countless millions of man-hours of effort rewriting stable code for no good reason?

        Tough choice!

        • Re:Huh? (Score:5, Funny)

          by ArchieBunker ( 132337 ) on Sunday September 04, 2022 @09:59PM (#62852499)

          Python says hold my beer!

          • In ascii art, braces can be hands. Python ain't holdin nobody's beer.

        • Re:Huh? (Score:5, Funny)

          by narcc ( 412956 ) on Monday September 05, 2022 @01:23AM (#62852719) Journal

          If only there was some command that you could use to find scripts that made use of egrep and fgrep...

        • by AmiMoJo ( 196126 )

          Problem is that on some systems they are already aliases to grep, but on others they are binaries. Binaries that have been unsupported and unmaintained for years.

          Particularly with scripts that are distributed, e.g. as part of a larger software package, there is a risk that they run on systems with old binaries that have security issues. Scripts for things like installing software or editing settings often run at higher than normal privilege levels too.

        • GNOME, which is GNU, went systemd (which is not GNU) rather than make good decisions.

          At this point we can count on GNU to make bad decisions, like in this case not volunteering to deliver wrapper scripts to provide these functions in the grep distribution.

          egrep and fgrep date from Version 7 Unix, from 1979. This decision literally breaks scripts older than the GNU project.

          It's a valid question whether any of those are still being used today, but this still doesn't make any sense at all.

        • by jmccue ( 834797 )
          are you using the original csh(1) ?
      • I'm rather amazed to hear that I had no idea egrep/fgrep were deprecated. I'm not exactly sure how I'd ever find out though - unless using them emits a warning (which would really break compatibility). Maybe slashdot posted a story about it 15 years ago and I missed it, or maybe it didn't - but it's taken me this long to know about it.

        I'm now wondering what egreps I've used in the last 15 years - quite a few, I'm sure. I always though they were equivalent and symlinked/linked together, with grep just emulat

    • by _xeno_ ( 155264 )

      Can't they just make egrep and fgrep into aliases for grep with the appropriate command line parameter added?

      AFAIK they effectively already are. If you look at the commit that added the deprecation warning [gnu.org] you'll see that it was added to "egrep.sh".

      Wait, where's "fgrep.sh"? Well, it's also "egrep.sh", as "egrep.sh" uses compile-time substitution to serve as both on install, and all it does is launch "grep" with either -F or -E as appropriate. (In fact, you can see the part of the Makefile.am for building the final egrep and fgrep stubs immediately before the egrep.sh changes as they have a minor change as well.)

      So

      • Re:Huh? (Score:4, Insightful)

        by mysidia ( 191772 ) on Monday September 05, 2022 @12:14AM (#62852651)

        I suppose it's "more optimal" to just call "grep" directly because it avoids running a second shell to build the new "grep" command

        Also silly to turn it into a shell script. IMO software distributions should freeze on what version Grep will ship to one before the dumb warning was added and just start declining any further updates from the maintainers of grep (Keep the old version.. Are these new maintainers anyways who are bored and just trying to stir something up, or what?). Grep is already feature complete - any changes at this point other than bugfixes or performance tweaks are basically just doing everyone a disservice. I don't think there is Anything the maintainers could possibly add to the software at this point that would have a benefit worth the cumulative pain of the change.

        Grep could easily check its command line opts and automatically set a flag if argv[0] ends with fgrep or egrep. This is what BSD Grep does and what I thought Linux was doing for a long time.. on MacOS fgrep, egrep, and grep are Identical binaries. On other systems fgrep and egrep are just symlinks to grep.

        • I just wrote a bad comment insisting they should include wrapper scripts :D

          There is literally no reason to be bad at a wrapper script. None. It will do exactly the same job.

          As usual, which I should have expected, this is a fart in a fart factory.

      • Re:Huh? (Score:5, Insightful)

        by ufgrat ( 6245202 ) on Monday September 05, 2022 @01:59AM (#62852749)

        Remember the old days when programs would check $0, and depending on the name used, behave differently?

        Now we have to write a shell script, AND so that the braindamaged linux admin wannabes know it's a shell script, it has to end in ".sh", when an alias, or a bit of code that causes grep to run itself as "-E" when invoked as "egrep", would work just as well.

        It's like modern Unix programmers don't actually grok Unix.

        • The Unix principle was to keep it simple. GNU/Linux followed those ideals. Systemd is not simple. It goes against the very principles of Unix.

          Magic was just that. Who needs extensions?

          As a side note: As someone pointed out. Ubuntu already has shell scripts to replace egrep/fgrep. They've been gone a while.

          Those who don't grok Unix, almost certainly won't grok, grok?

          • The Unix principle was to keep it simple.

            The first use of that principle was in 2003 in Raymond's book. I think you'll find Unix predates that principle, and Unix is filled chock full of systems that are far from simple. Case in point: SysV init which failed to do its one task and relied on complex scripts and even third party tools to do the bare minimum of managing system daemons, or X11 a system so complex that it was abandoned by many of its developers as unmaintainable.

            If you want get more specific an older and different set of Unix principle

            • It's good software development practice in general, often expressed within the dev world as the Single Responsibility Principle ("SRP").

              Much of software maintenance consists of refactoring fusty code that has been Band-aided, updated, and added to gradually over long periods of time, so that it comes closer to obeying the SRP.

              What does happen sometimes is that people remove what they think is unnecessary complexity in one place, only to have it reappear in others, sometimes in a worse form. Thus, over time

      • On Gentoo, they are already scripts:

        # file `which egrep` /bin/egrep: POSIX shell script, ASCII text executable

    • by jaa101 ( 627731 )

      into aliases for grep with the appropriate command line parameter added?

      You don't even need to add command-line parameters; commands can examine argument zero to find out the command that was used to run them and adjust their behaviour accordingly. Then you just make grep, egrep, and fgrep hard links to the same binary.

      But my Ubuntu 20.04.3 LTS already has egrep as a shell script with just 'exec grep -E "$@"' as you suggest.

    • You just make grep, egrep and fgrep hard links to the same file. The argument processing logic first checks argument $0, the file name that was called, and add -F or -E to the arguments as needed.

      This is what stock bsd grep does - note the identical inode numbers -

      $ls -i /usr/bin/grep
      15918623 /usr/bin/grep
      $ls -i /usr/bin/egrep
      15918623 /usr/bin/egrep
      1$ls -i /usr/bin/fgrep
      15918623 /usr/bin/fgrep

      • by jmccue ( 834797 )

        On OpenBSD that is what is already being done.

        I do not know why GNU cannot use hard links like you say. It is not like it is rocket science.

        • by jmccue ( 834797 )
          embarrassed, in true /. fashion I did not read the full comment :) I missed the 'bsd'
    • by jmccue ( 834797 )

      You are forgetting scripts, yes you can use aliases for interactive use, but many scripts may need to be changed.

      Yes you can alias that in the user I and modify your ID to ensure cron gets that alias, but issues can happen if you try [ef]grep with some quoting, and should you use execv(3) with [ef]grep, aliases will not work.

  • What about agrep (Score:5, Interesting)

    by u19925 ( 613350 ) on Sunday September 04, 2022 @08:57PM (#62852385)

    "agrep" is the only grep software that I have been using since 1993. It has quite a few unique features not yet available in grep/fgrep/egrep. Ability to provide delimiter, search in binary files, approximate grep and so on. In 1993, it was also about 10 times faster than standard grep.

    I became die hard fan when I was doing a research and we had to upload the paper for publication in 4 hours and realized that due to a software bug the data in our tables were wrong. The data were extracted using a software from over 1000 binary files, each about 5 MB. Introspecting the files, I found that most files had the required data in the first few blocks but there was no guarantee. I modified agrep to take "-l" option and also print a record and use a delimiter to extract the required data. The whole process less 2 hours (actual execution time only 30 min). I still can't think of anything else can do the required job even today.

    I ported this to Windows in 1995. Since it is written with direct unix syscalls, compiling was a challenge. Then I noticed that MS Visual C++ 2.0 was converting c calls to unix signature syscalls before converting to Win32 api calls. I included compiler's internal header files and viola, it worked (with lots of warnings from compiler for using internal headers). The only modification I did was to add Windows way of handling command line args. Unfortunately, I lost the source code when the hard disk crashed. Since I had copied the binary to multiple machines, it survived. Believer it or not, I am still using that on my Windows machines but I can't distribute it.

    • by u19925 ( 613350 )

      I am mostly Mac user now last few years but still have one Window machine at home. The agrep compiles fine on all Macs including M1 Macs.

    • Was anyone listening to Rythm Nation when the HDD crashed?
    • Which agrep do you mean? There's an older one and there is the more recent TRE agrep, which has some very nice features.
    • I included compiler's internal header files and viola, it worked (with lots of warnings from compiler for using internal headers)..

      Did you use a big violin to compile C code? This is news for nerds.

  • by zoid.com ( 311775 ) on Sunday September 04, 2022 @09:31PM (#62852459) Homepage Journal

    try Silver Search. It is so much faster than grep.
    https://github.com/ggreer/the_... [github.com]

  • by dskoll ( 99328 ) on Sunday September 04, 2022 @09:44PM (#62852477) Homepage

    What good does this change do? It removes at most a couple of dozen lines of code that haven't changed in probably over a decade. It's not like this reduces the support burden of grep much. It seems to me like a gratuitous change that will just annoy users.

  • by anomaly256 ( 1243020 ) on Sunday September 04, 2022 @09:47PM (#62852481)
    "In addition, the developers advise that the general public have been mispronouncing using a hard 'g' and should instead be using a soft 'g' as in 'just' or 'GIF'"
  • by thesjaakspoiler ( 4782965 ) on Sunday September 04, 2022 @11:11PM (#62852577)

    Why are people still using egrep and fgrep you can all do that with systemd while it brings World Peace at the same time?

    • If people could shoot each other over an internet forum not only would systemd not bring about World Peace, Slashdot itself would be a R-rated bloodbath!

      Well MA rated. Not a lot of boobs here.

  • by eneville ( 745111 )

    Some people will switch to ripgrep.

    • Feels like Rust is slowly taking over the cli world. Rust haters deny it, but they also tend to think POSIX compliance is the only way to go, null should terminate all strings, etc.

  • Not just removing a couple of aliases/hard links, but also giving me the opportunity to check my code for use of GREP_COLOR. And just when I was at a loose end!

  • This is your two-decade warning, You have twenty years left before egrep/fgrep support is utterly and finally removed forever. Don't dawdle, folks, this is not a drill!

    • Oh no! raise the alarm! This means war! Waaa-ah-ah! lolol

      ROFLCOPTER

      Some of these whiners should learn how to computer, they could fork it or make an alias or something.

  • I do use egrep quite often, not because I could not do it with command-line switches, but for clarity.
  • I am not sure all of this egrep and fgrep business is important in the wider scheme of things. I am bloody sure that the world is a better place if you can crunch your data files with simple tools such as grep, rather than depending on vendor-specific tools. At the risk of going off-topic, one of the reasons I hate systemd is that it is not greppable. Frankly, I do not have a clue what is going on, because my usual investigative tools just don't work any more. Boot scripts using Bash could be pretty obscure

  • "You can't grep dead trees"
  • More of this ! and less about Apple's new baubles or Code.org's latest attempt to keep boys from programming or some dumb new unreplicated psychological research that shows nothing.

  • Comment removed based on user account deletion

Ocean: A body of water occupying about two-thirds of a world made for man -- who has no gills. -- Ambrose Bierce

Working...