4 ms·
Aside: What do you mean by "use a symbolic link" (I'm familiar with `ln -s` fwiw) the alias carries the command switch, how do you do that with a link? #
by pbhjpbhj 4y ago
Aside:
What do you mean by "use a symbolic link" (I'm familiar with `ln -s` fwiw) the alias carries the command switch, how do you do that with a link?
# example
alias egrep='grep -E'
??
- PaulHoule 4y agoA program like "grep" gets the path to the binary in argv[0], if it sees that argv[0] is something like /some/path/fgrep it adds the -E flag. A hard link works OK too, as done copying the whole binary.
- anamexis 4y agoThis is not the case for GNU grep. It appears only some BSDs do this.
- vlovich123 4y agoYou use argv0 to check the program name. The utility has to support it in code which GNU apparently dislikes as someone mentioned elsewhere in the thread.
- mananaysiempre 4y agoCurrently, egrep and fgrep are shell scripts (the too-simple version of this idea would be #!/bin/sh exec /usr/bin/grep -E "$@" but that would mess up help messages and probably also needs disaster handling in case exec fails). Another traditional way, however, is to symlink everything to a single binary, which uses argv[0] or getprogname() to see which name the user called it under and acts accordingly. In the extreme case, you get the "multi-call binaries" Busybox or Toybox, which contain an entire set of Unix utilities in a single (not-too-slim) executable image. GNU grep also used that technique at some point in its history, but it was discarded for a reason I don't recall.
- smellf 4y agoActually it turns out that, at least in debian 11, you were right on the money: cat `which egrep` #!/bin/sh exec grep -E "$@" But I agree that it would be cleaner and trivial to implement this behavior by depending on argv[0], GNU style guide be damned.