Genivia / ugrep

NEW ugrep 6.5: a more powerful, ultra fast, user-friendly, compatible grep. Includes a TUI, Google-like Boolean search with AND/OR/NOT, fuzzy search, hexdumps, searches (nested) archives (zip, 7z, tar, pax, cpio), compressed files (gz, Z, bz2, lzma, xz, lz4, zstd, brotli), pdfs, docs, and more
https://ugrep.com
BSD 3-Clause "New" or "Revised" License
2.56k stars 109 forks source link

default GNU grep uses -G for basic regexp #405

Closed Konfekt closed 2 months ago

Konfekt commented 2 months ago

Referring to https://github.com/Genivia/ugrep?tab=readme-ov-file#why-use-ugrep

Ugrep is a true drop-in replacement for GNU grep

While ugrep -G interprets, say \(a1\|a2\)b\+ as basic regexp, ugrep does not, though -G is the standard switch? Tested with GNU grep 3.7 on Opensuse 15.5

genivia-inc commented 2 months ago

The default is -E for egrep. See ugrep.com.

If you read the README from which this is quoted "Ugrep is a true drop-in replacement for GNU grep", then it says it is a drop-in replacement if you copy or rename ugrep. When you copy or rename ugrep to grep then it behaves as grep (with -G). Likewise, copy ugrep to fgrep and it behaves as fgrep.

Or alias grep=ugrep -G works fine.

The choice to make -E the default is because ERE is more common these days and also Perl/PCRE syntax is ERE.

Konfekt commented 2 months ago

Okay, still getting used to executables behaving differently depending on how they are named (or which symlink called them!?)

genivia-inc commented 2 months ago

Symlinking ug or ugrep to grep generally works, but there are problems with bash when it does not propagate the grep name to argv[0], which ugrep checks internally. Instead, bash propagates the symlinked target name ugrep. This is not good. This was a surprise to me too.

It may work when symlinking from a home bin dir that is on your path, but not when installing the symlinked grep command on a system path.

To check if ug or ugrep properly sees the symlinked name grep, option --version should tell you it is in "grep emu mode":

$ grep --version
ugrep 6.1.0 aarch64-apple-darwin21.6.0 (grep emu mode) +neon/AArch64; -P:pcre2jit; -z:zlib,bzip2,lzma,lz4,zstd,brotli,7z,tar/pax/cpio/zip