argv[0] contains command name -- why? [Archive] - C Board

PDA

View Full Version : argv[0] contains command name -- why?


Billy123
04-12-2008, 12:19 AM
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.

laserlight
04-12-2008, 12:30 AM
Because the C and C++ standards say that it can.

Billy123
04-12-2008, 12:42 AM
Fair enough... thanks.

birkelbach
04-12-2008, 11:53 AM
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.