LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Not having to prepend compiled commands with ./? (https://www.linuxquestions.org/questions/linux-newbie-8/not-having-to-prepend-compiled-commands-with-649742/)

SirTristan 06-16-2008 05:47 PM

Not having to prepend compiled commands with ./?
 
How can one make it so that compiled commands can be executed without having to prepend them with './'? For instance given the g++ compiled command a.out, executing with just 'a.out' instead of './a.out'.

weibullguy 06-16-2008 05:58 PM

You would have to add the directory where you built the command to your PATH variable. For example, if you are compiling in /home/SirTristan/neatstuff, then you would need to add /home/SirTristan/neatstuff to PATH. The other option is to tell g++ to output the executable to a directory that is in your PATH (and you have write permissions) using the -o switch.

jailbait 06-16-2008 06:02 PM

Put the directory where the command resides on your PATH. You can show your PATH with:

echo $PATH

You can add a directory (for example /home/user/test) to your PATH with:

PATH=$PATH:/home/user/test
export PATH

-------------------
Steve Stites

camelrider 06-17-2008 03:04 AM

When you prepend ./ to a command you are telling bash to look for the command in the current directory.

You could add . to your $PATH, but this is considered a poor move security-wize. There used to be quite a bit of discussion on the old linuxnewbie.org forums about the pros and cons of this practice.

knudfl 06-17-2008 03:31 AM

Suggest : rename a.out to something else and move or copy it
to /usr/local/bin
(If you only have 1 a.out, the name a.out is OK)
Then it is in your path.

Rgds

brianL 06-17-2008 06:11 AM

What's so arduous about having to type two extra characters anyway? ./ there, even a lazy **** like me can do it. :)

jschiwal 06-17-2008 06:23 AM

If these are useful programs you will use again, create a bin dir in your $HOME directory and add $HOME/bin to your path.

The system profile script may even check for a $HOME/bin directory and add it to the path if it is present.
You can put handy scripts in there as well.

SirTristan 06-17-2008 02:44 PM

Quote:

Originally Posted by jschiwal (Post 3187212)
If these are useful programs you will use again, create a bin dir in your $HOME directory and add $HOME/bin to your path.

The system profile script may even check for a $HOME/bin directory and add it to the path if it is present.
You can put handy scripts in there as well.

Good idea, thanks :)


All times are GMT -5. The time now is 11:08 AM.