2

When I run egrep, it shows warning: egrep is obsolescent; using grep -E

But I'm using it as part of my shell autocomplete script that I often use, and I don't want to rewrite them.

I'm looking for way to suppress those warnings, since my autocomplete become 'ugly', e.g.: when typing mycmd myargum<TAB>, I'm expecting autocomplete to make it mycmd myargument, but instead it writes:

mycmd myargum<TAB>grep: warning: egrep is obsolescent; using grep -E
grep: warning: egrep is obsolescent; using grep -E
ent

Currently I tried doing this:

mv /usr/bin/egrep /usr/bin/egrep.backup
echo 'grep -E $@' > /usr/bin/egrep
chmod a+x /usr/bin/egrep

It works by changing the grep binary to a script that calls 'grep -E' instead.

Additional info:

$ egrep.backup --version
egrep.backup: warning: egrep.backup is obsolescent; using grep -E
grep (GNU grep) 3.8
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and others; see
<https://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

The question is:

  • Is this method okay? Will it have unintended consequences?
    • Maybe it will make egrep.backup binary still undeleted if grep package is uninstalled/purged, but this should be non issue as I never planned to do that
  • Is there any better way to suppress this warning message?
4
  • 3
    after a quick search, I realized that I can just make alias egrep="grep -E" in .bashrc since alias is prioritized over $PATH from unix.stackexchange.com/a/132628/477417
    – Kristian
    Commented Dec 8, 2022 at 3:54
  • 1
    or, better yet, you could modify your scripts that use the obsolete egrep so that they use grep -E instead. egrep has been deprecated for decades now, that's more than enough time to stop using it.
    – cas
    Commented Dec 8, 2022 at 4:58
  • 3
    Use echo 'grep -E "$@"' > /usr/bin/egrep, ie double quote the $@ Commented Dec 8, 2022 at 6:49
  • What will you do when egrep is completely removed? Commented Dec 8, 2022 at 15:30

1 Answer 1

8

In GNU grep, egrep and fgrep are shell scripts anyway; starting with 3.8, these are where the obsolescence warning is produced:

#!/bin/bash
cmd=${0##*/}
echo "$cmd: warning: $cmd is obsolescent; using grep -E" >&2
exec grep -E "$@"

Replacing them with your own version is fine; the previous version was

#!/bin/sh
exec grep -E "$@"

(with an obvious variant for fgrep).

The only aspect to watch out for is that your packaging system still “owns” the egrep and fgrep binaries, so you’ll lose your changes whenever the package is upgraded. To avoid that, you can tell the packaging system that it no longer owns the files; in Debian derivatives, run

sudo dpkg-divert --divert /usr/bin/egrep.original --rename /usr/bin/egrep
sudo dpkg-divert --divert /usr/bin/fgrep.original --rename /usr/bin/fgrep

This will cause the packaging system to always rename the packaged file to ?grep.original.

(Curious readers may want to read the bug report which led to these warnings, and a few bug reports filed as a result.)

1
  • 1
    Strange that they would use a bash shebang when there's nothing bash-specific in there. That adds an unnecessary dependency to that shell. That means however that one could call egrep as: env 'BASH_FUNC_echo%%=() { :; }' egrep to remove that warning. You could make your replacement script #! /bin/bash - / exec -a "$0" grep -E "$@" for it to mention egrep in its error messages. Commented Dec 8, 2022 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .