Live data from Hacker News

(Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

phoronix.com

21–27 of 27 posts

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#21

An alias also seems like it'd work. alias egrep='grep -E' alias fgrep='grep -F'

POSIX 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.

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#22
post #20
post #17

Earlier quoted context omitted.

GNU 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…

Thanks for the lineup! Seems quite the waste that this would change every five years. So removing seems a good option. I didn't like the arg0 magic, so I'm happy that is gone. Funny to think I had to be in the right time window to even notice that.

What is your objection to argv[0]?

Gzip and its successors have used this technique for decades, and busybox wouldn't exist without it.

On Android, take a look at /system/bin, to find this approach still very much used.

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#23
post #22
post #20

Earlier quoted context omitted.

Thanks for the lineup! Seems quite the waste that this would change every five years. So removing seems a good option. I didn't like the arg0 magic, so I'm happy that is gone. Funny to think I had to be in the right time window to even notice that.

What is your objection to argv[0]? Gzip and its successors have used this technique for decades, and busybox wouldn't exist without it. On Android, take a look at /system/bin, to find this approach still very much used.

After A bit of thought it does not bother me.

But I can see why it could bother people, the idea that a function changes based on it's name is weird, after all the name is just a symbolic identifier, it should not matter if the name is "search" or "grep" it should do the same thing.

But I decided it does not matter, mainly because names are really important, so important that changing the name effectively changes the function, for example if you took the sin() and renamed it destroy_universe() there would be so much uncertainty about both the new name and the lack of the old, that it does not matter that the code is the same, you have to now treat them different, so having code that does different things based on the name is fine.

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#24
post #12

Earlier quoted context omitted.

I 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 "$@"

interesting, 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

[deleted]

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#25
post #12

Earlier quoted context omitted.

I 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 "$@"

interesting, 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

I hadn’t realized the bsd’s implemented egrep and fgrep. Even more reason not to depreciate the interface.

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#26
post #23
post #22

Earlier quoted context omitted.

What is your objection to argv[0]? Gzip and its successors have used this technique for decades, and busybox wouldn't exist without it. On Android, take a look at /system/bin, to find this approach still very much used.

After A bit of thought it does not bother me. But I can see why it could bother people, the idea that a function changes based on it's name is weird, after all the name is just a symbolic identifier, it should not matter if the name is "search" or "grep" it should do the same thing. But I decided it does not matter, mainly because names are really important, so important that changing the name effectively changes the…

Android uses toybox, because the license is more permissive.

https://landley.net/toybox/about.html

Here is the output from my phone (notice the applets for egrep and fgrep):

127|:/ $ toybox

[ acpi base64 basename blkdiscard blkid blockdev cal cat chattr chcon chgrp chmod chown chroot chrt cksum clear cmp comm cp cpio cut date dd devmem df diff dirname dmesg dos2unix du echo egrep env expand expr fallocate false fgrep file find flock fmt free freeramdisk fsfreeze fsync getconf getenforce getfattr getopt grep groups gunzip gzip head help hostname hwclock i2cdetect i2cdump i2cget i2cset iconv id ifconfig inotifyd insmod install ionice iorenice iotop kill killall ln load_policy log logname losetup ls lsattr lsmod lsof lspci lsusb makedevs md5sum microcom mkdir mkfifo mknod mkswap mktemp modinfo modprobe more mount mountpoint mv nbd-client nc netcat netstat nice nl nohup nproc nsenter od partprobe paste patch pgrep pidof ping ping6 pivot_root pkill pmap printenv printf prlimit ps pwd pwdx readelf readlink realpath renice restorecon rev rfkill rm rmdir rmmod rtcwake runcon sed sendevent seq setenforce setfattr setsid sha1sum sha224sum sha256sum sha384sum sha512sum sleep sort split stat strings stty swapoff swapon sync sysctl tac tail tar taskset tee test time timeout top touch tr traceroute traceroute6 true truncate tty tunctl ulimit umount uname uniq unix2dos unlink unshare uptime usleep uudecode uuencode uuidgen vconfig vi vmstat watch wc which whoami xargs xxd yes zcat

Re: (Changes to grep) Time To Stop Using egrep and fgrep Commands, Per GNU grep 3.8

#27
post #22
post #20

Earlier quoted context omitted.

Thanks for the lineup! Seems quite the waste that this would change every five years. So removing seems a good option. I didn't like the arg0 magic, so I'm happy that is gone. Funny to think I had to be in the right time window to even notice that.

What is your objection to argv[0]? Gzip and its successors have used this technique for decades, and busybox wouldn't exist without it. On Android, take a look at /system/bin, to find this approach still very much used.

Hm, I just dislike magic like that. It tends to go wrong in weird ways. If I'd compile it and symlink to it as fgrep-gnu for example. But of course, the wrappers would be even more confusing, executing the system grep, not the compiled grep. So removing the wrappers is fine.
Post reply on HN