Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
What does “/” , “./”, “../” represent while giving path?

Why do I need ./ for commands to run on Mountain Lion?

For example, when using mysql I have to type in the terminal:

./mysql -u itsme -p

Also, I'm creating command line applications and make my files executable and I do have to run the command with ./, like this...

./myawesomeapp dothis

I know ./ means current directory, but how can I run commands without having to use it?

share|improve this question

migrated from stackoverflow.com Jan 25 '13 at 18:28

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Daniel Beck Jan 25 '13 at 18:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
@cdhowie It's a programming question if it arises in building an executable on the command line. –  Potatoswatter Jan 25 '13 at 16:51
1  
@Potatoswatter No, it's not. That's flawed logic. I could use that same argument to argue that just about any computer-related topic is on-topic on SO. –  cdhowie Jan 25 '13 at 16:53

3 Answers 3

Whilst it is possible to add . to your $PATH variable, it is highly recommended NOT to do that. If you walk around to some random place in the filesystem and type something that you think will run a program (vi, emacs, ls, ps, etc), a file in the local directory will become a candidate to run. If you are unlucky, that's NOT the program you wanted to run at all - and if you are running as root, it's even worse, because someone may well add a local file ls that does something completely different than real ls (along with doing real ls, of course - otherwise it would be obvious that it's not real ls, and the user would start investigating the situation). [1]

Instead, you should add an absolute path to where you have your executable files, e.g. /projects/mycurrentprojects/bin - or "relative to home", e.g. ~/bin - if you want the path to work in ALL circumstances it's better to use home\mats\bin [obviously using the right username for yourself]. That way, only files in a certan set of directories are applicable, and no matter where you are, only programs that are in those specific directories are chosen as "possible candidates to run".

[1] Yes, I realize that the search order and various other factors will also matter here. But it's generally not a great idea to add "current directory", no matter what objections.

share|improve this answer
    
The tilde ~ might not always expand, causing frustration. Its substitution is done by shell programs, while various other kinds of environments may use PATH. –  Potatoswatter Jan 25 '13 at 16:58
    
Good point. So may be better to write out /home/mats/bin - editing... –  Mats Petersson Jan 25 '13 at 17:01

You have to install the executable file in one of the directories listed in the environment variable $PATH.

echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin

Adjust $PATH by modifying your ~/.profile file.

export PATH=$PATH:/Users/me/bin

It is possible to forgo the ./ always by adding . to $PATH, but that could be a security issue — if not on your personal machine, then when you carry the bad habit over while operating a server.

share|improve this answer

If you put the directory with your binaries into your PATH environment variable, you can call them without providing the path (ie the ./)

I'd guess you're probably using bash as your shell (you can check by running echo $SHELL). If that's the case, add the following to your .bashrc

export PATH=$PATH:/whatever/path/you/want/to/add
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.