0

I am using RASPBIAN on my raspberry pi. I find out that the command "apropos" is a symbolic link of the command "wahtis". However, the output of those commands do not match when used with the same arguments:

$ whatis delete
delete: nothing appropriate.

but

$ apropos delete
argz_delete (3)      - functions to handle an argz list
delete_module (2)    - unload a kernel module
dphys-swapfile (8)   - set up, mount/unmount, and delete an swap file
git-branch (1)       - List, create, or delete branches
git-replace (1)      - Create, list, delete refs to replace objects
git-symbolic-ref (1) - Read, modify and delete symbolic refs
git-tag (1)          - Create, list, delete or verify a tag object signed 
***output is truncated to save space....***

It is clear that the apropos is a symbolic link of whatis.

pi@raspberry:~ $ which apropos
/usr/bin/apropos
pi@raspberry:~ $ ls -l /usr/bin/apropos
lrwxrwxrwx 1 root root 6 Aug 24  2017 /usr/bin/apropos -> whatis

How can that happen?

1 Answers1

5

The running executable will know the full invoking commandline, and can modify its behavior depending on the name by which it was called. For the specific instance of apropos/whatis, you can see in the source code (around line 895 of the linked recent version) that the first thing that is done is to determine whether the command was called by the name apropos or not:

int main (int argc, char *argv[])
{
#ifdef HAVE_ICONV
    char *locale_charset;
#endif
    int status = OK;

    program_name = base_name (argv[0]);
    if (STREQ (program_name, APROPOS_NAME)) {
        am_apropos = 1;
        argp_program_version = "apropos " PACKAGE_VERSION;
    } else {

There about a dozen places further in the processing which check the am_apropos flag, and behave differently depending on whether or not it has been set.

user4556274
  • 8,995
  • 2
  • 33
  • 37
  • Thank you very much. Your answer is pretty helpful. I am not deeply involved in Linux programming but I couldn't imagine that the executable may check the invoked name! Good to know. Thank you. – Amjad Abdullah May 01 '18 at 13:58