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?

  • What is the output of which whatis? If it is not /usr/bin/whatis, then the symbolic link does not point to the command you are running. Alternatively, does /usr/bin/whatis delete return what you expect? (Same effective check, different tack) – cunninghamp3 Apr 30 '18 at 19:53
  • 2
    The running executable will know the full invoking commandline, and can (if it desires) modify its behavior depending on the name by which it was called ($0). – user4556274 Apr 30 '18 at 19:58
  • 1
    Related: Why does argv include the program name? – steeldriver Apr 30 '18 at 19:59
  • Other programs that do this, partial list: vim/vi; bash/sh. – DopeGhoti Apr 30 '18 at 20:00
  • Yes, and that can be used intentionally, for example, busybox may install one binary and create several symlinks, for the different utilities implemented in busybox. The binary knows what to do based on argv[0]. – njsg Apr 30 '18 at 20:00
4

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.

  • 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 1 '18 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.