LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2008, 06:47 PM   #1
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
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'.
 
Old 06-16-2008, 06:58 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
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.
 
Old 06-16-2008, 07:02 PM   #3
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Jessie, Linux Mint 17
Posts: 7,751

Rep: Reputation: 272Reputation: 272Reputation: 272
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
 
Old 06-17-2008, 04:04 AM   #4
camelrider
Member
 
Registered: Apr 2003
Location: Juneau, Alaska
Posts: 247

Rep: Reputation: 31
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.
 
Old 06-17-2008, 04:31 AM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154
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
 
Old 06-17-2008, 07:11 AM   #6
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 7,453
Blog Entries: 55

Rep: Reputation: Disabled
What's so arduous about having to type two extra characters anyway? ./ there, even a lazy **** like me can do it.
 
Old 06-17-2008, 07:23 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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.
 
Old 06-17-2008, 03:44 PM   #8
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Suse Linux Commands For These Aix Commands? Vaskar Guha Linux - Software 2 12-19-2005 01:45 AM
bash 'prepend' script linmix Programming 31 12-02-2005 04:53 PM
Prepend # for certain line numbers in VI twantrd Linux - Software 3 09-05-2005 02:27 PM
prepend char to a string schneidz Programming 6 06-01-2005 09:53 AM
are these compiled shanenin Linux - Software 1 10-16-2003 12:11 PM


All times are GMT -5. The time now is 01:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration