Invoke a program as a command on any working directory on ubuntu's terminal

I have written a program in C and produced an executable from it. I want to use this program from any pwd. One method is to make its pathname a environment variable using export. But in this method, everytime I want to invoke my program, I need to prefix my command word with $. I want my command to work like in-build commands like cat, grep, awk, top, man, etc.

Let’s say my command is myprog.

$ myprog arg1 arg2

this command should invoke my executable from any directory as the pwd in the terminal.

Asked By: Cinverse


Copy your program into your $HOME/bin directory. Next login your $PATH should contain your bin dir, so the program should work as you described.

Answered By: ubfan1