argv[0] contains command name -- why?

This is a discussion on argv[0] contains command name -- why? within the Linux Programming forums, part of the Platform Specific Boards category; Hello, I'm trying to figure out specifically WHY argv[0] contains the command name. I've done a bit of searching and ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    2

    argv[0] contains command name -- why?

    Hello,

    I'm trying to figure out specifically WHY argv[0] contains the command name. I've done a bit of searching and all I can find is that it's a convention, but I'm thinking that there must be another reason. Please let me know if I'm wrong.

    Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,650
    Because the C and C++ standards say that it can.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    2
    Fair enough... thanks.

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    19

    Symbolic Links

    Many programs are called by symbolic (or hard) links of different names. An example is 'vim.' The executable name is 'vim' but there is usually a symbolic link named 'vi'. The program checks argv[0] to see how it was called. If it was called with 'vi' it acts like 'vi' else it acts like 'vim'. Busybox also uses this technique so that it can use one executable to pretend to be may of the normal *nix utilities that we know and love.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. use of softlink and argv[0]
    By MK27 in forum C Programming
    Replies: 14
    Last Post: 02-24-2009, 03:56 PM
  2. Replies: 12
    Last Post: 02-10-2009, 01:14 PM
  3. main() ; argv[1] = string at argv[0]???
    By UCnLA in forum C Programming
    Replies: 1
    Last Post: 03-31-2008, 12:16 AM
  4. argv[0] with WinMain()
    By dwks in forum Windows Programming
    Replies: 4
    Last Post: 03-05-2006, 11:41 AM
  5. change argv[0] after fork
    By garion in forum C Programming
    Replies: 2
    Last Post: 02-05-2006, 09:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21