SittingBull SittingBull - 4 months ago 9
Bash Question

How do I execute my program without ./a.out command?

I have written a c program. I want to pipe the program and I want to make it look meaningful. So instead of writing

./a.out
each time, I want to name it
changetext
. To achieve that, I compiled my program following way:
gcc -o changetext myprog.c
. To the best of my knowledge, this should replace the use of
./a.out
and
changetext
should do that instead. But I'm getting
command not found
. I am new to c and unix environment. Any suggestion appreciated.

Answer

As I said in a comment, you can either put a dot slash (./) in front of the executable to run it

./changetext

Or you put in in a directory that is referenced in the PATH environment variable. A nice explanation of this safety feature can be found here (thanks to rubenvb):

http://www.linfo.org/dot_slash.html

It says that this is more or less to distinguish built-in commands from user-written commands with the same name. I am not convinced though. The shell could simply prefer built-in names to user-supplied ones, and look in the current directory as well as in the PATH.

But this is the *nix way.