On Mon, Nov 18, 2024 at 11:57:05 +0100, Arno Lehmann wrote: > Am 18.11.2024 um 11:45 schrieb Yassine Chaouche: > > Dear debian and linux enthusiasts, > > > > Have you ever stopped and wondered: > > Are `/usr/bin/[` and `/usr/bin/test` truly unique across all unices? > > interesting question (and observation below). I can't say I ever really > cared, and I'm not even sure now. But: > > $ LANG=C /usr/bin/\[ --help | head -n 2 > Usage: test EXPRESSION > or: test > > is also nice to find. > > > Unfortunately, I'm not brilliant at all. > > But I'm eager to see if Greg has something to educate us ;-)
POSIX doesn't care whether you ship separate binary files or a single binary file to implement commands. It's the implementor's choice; in this case, the implementor is GNU coreutils. If you go back far enough in time, you'll probably find that the two programs shared a single binary file, and either used a hard link or a symbolic link from one to the other. That was fashionable in the past, primarily as a means of reducing disk space usage. In recent years, GNU has tried to do away with the whole "this program may be invoked by any of the following names, and it changes it behavior based on which name it finds in argv[0]" approach. From <https://www.gnu.org/prep/standards/standards.html#Standards-for-Interfaces-Generally>: 4.5 Standards for Interfaces Generally Please don’t make the behavior of a utility depend on the name used to invoke it. It is useful sometimes to make a link to a utility with a different name, and that should not change what it does. Thus, if you make foo a link to ls, the program should behave the same regardless of which of those names is used to invoke it. Instead, use a run time option or a compilation switch or both to select among the alternate behaviors. You can also build two versions of the program, with different default behaviors, and install them under two different names. If you look around a bit, you'll find that commands which *used* to share a common file (grep/egrep/fgrep, gzip/gunzip/zcat) have started shipping a single compiled binary file and a set of wrapper shell scripts for the alternative names. E.g.: -rwxr-xr-x 1 root root 41 Jan 24 2023 /usr/bin/egrep -rwxr-xr-x 1 root root 41 Jan 24 2023 /usr/bin/fgrep -rwxr-xr-x 1 root root 203152 Jan 24 2023 /usr/bin/grep A wrapper script can't be used to differentiate test and [, however, because of the way the final argument is treated.