PDA

View Full Version : How to execute a binary/script in Linux without a "./" in front of it?


oi u agree
09-12-2011, 05:22 PM
For example, I just compiled a C++ program that uses command line arguments. However, everytime I want to run it, I have to type "./" in front of it, i.e. "./runit argument1 argument2" in order to run the program. How do I make it so that I don't have to type ./ in front of it every time?

Levi
09-12-2011, 05:39 PM
If I remember right, its something like

export PATH=$PATH:./

Put that in your .bashrc

sad_ism
09-12-2011, 05:42 PM
Ya gotta add it to some folder in root, to make it recognized immediately by bash. Maybe /usr or /bin/ or /usr/local/bin ?

Modiga-Disabled
09-12-2011, 05:45 PM
http://home.ubalt.edu/abento/linux/terminal/addtopath.html

That should do it. Although I was shown to do it by editing the .bashrc file. I'm not sure which is the better option (I'm still a Linux noob).

bdmason
09-12-2011, 08:18 PM
http://home.ubalt.edu/abento/linux/terminal/addtopath.html

That should do it. Although I was shown to do it by editing the .bashrc file. I'm not sure which is the better option (I'm still a Linux noob).

The general idea is that if you are permanently adding executable files then you should add them to your .bashrc. If you are simply using the application on a short-term basis, it's better to just execute export PATH=$PATH:./ from the command line and run your programs and that export will disappear when you close that shell.

However, if you are permanently adding executable files, consider putting them in /bin or /usr/bin depending on how critical it is for system execution is. If memory serves, programs usually go into /bin if they are system-critical. i.e. something that helps the system boot or critical tools for using and maintaining the system. Programs that are not so critical go into /usr/bin.

Also, not many people know this, but in ubuntu if you add a "bin" directory in your home directory the system will automatically check to see if the program you want to run is in that directory without setting anything up. You don't even need to be in the same directory. I could be in /media/storage/scoobydoo and run the "shaggy" program and if shaggy is in /home/user/bin it will find it. At least that's how it works on my system and I never configured it special to do that.