Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invoke same program with different name?

Tags:

c

linux

I direct you to Kernighan & Ritchie exercise 7.1

Write a program that converts upper case to lower case or lower case to upper case depending on the name it is invoked with,...

How can I invoke the same program with different names?

I am using Linux, so I am invoking a compiled program just by entering:

$./a.out

What should I be doing differently?

like image 412
Tom Avatar asked Feb 05 '10 14:02

Tom


1 Answers

You should create a symbolic link, or just copy the executable of course:

Either

$ ln -s a.out A.out

or

$ cp a.out A.out

Then in your program's main(), inspect argv[0] to figure out how to act. This is a pretty useful technique, actually used often by production software.

like image 52
unwind Avatar answered Oct 23 '22 08:10

unwind