diff --git a/src/grep.c b/src/grep.c --- a/src/grep.c +++ b/src/grep.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "system.h" #include "argmatch.h" @@ -1938,6 +1939,7 @@ fgrep_to_grep_pattern (size_t len, char const *keys, int main (int argc, char **argv) { + char *ptr_c; char *keys; size_t keycc, oldcc, keyalloc; bool with_filenames; @@ -1984,6 +1986,19 @@ main (int argc, char **argv) compile = matchers[0].compile; execute = matchers[0].execute; + /* Check if executed through symlinks egrep/fgrep */ + if (argv[0] != NULL) + { + ptr_c = strchrnul(argv[0], ' '); + if (ptr_c - argv[0] >= 5) + { + if (strncmp(ptr_c - 5, "egrep", 5) == 0) + setmatcher ("egrep"); + else if (strncmp(ptr_c - 5, "fgrep", 5) == 0) + setmatcher ("fgrep"); + } + } + while (prev_optind = optind, (opt = get_nondigit_option (argc, argv, &default_context)) != -1) switch (opt)