C Language Main Method
- The C language main method can examine the contents of argv[*] before deciding what to do.
int main(int argc, char * argv[]) { printf("argv[0]==%s\n", argv[0]); if (strcmp(argv[0], "name1")) doName1(argc, argv); else if (strcmp(argv[0], "name2")) doName2(argc, argv); doPrg(argc, argv); }
- Suppose the program is named
prg
located in the current directory. - Suppose we established symlinks named
name1
andname2
. - This program can be invoked through the shell using one of three
names:
./prg
,./name1
, and./name2
. busysbox
uses this technique.