Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I'm just writing some small C scripts and testing them. Why dose

~ Desktop: gcc test.c -o test ; /Users/xx/Desktop/test ;

work just fine while

~ Desktop: gcc test.c -o test ; test ;

dose not work? Why dose OSX/ZSH need the full path to execute the binary?

share|improve this question

marked as duplicate by slhck Jul 6 '13 at 13:35

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.

This question is asked very often – please do a little research before asking. See also:…,… and… – slhck Jul 6 '13 at 13:38
Sorry, my bad! It was a dumb question, If I'd just thought about the call for a minute I could have realised myself that the call fails because it the new executable is not in $PATH. – wowpatrick Oct 28 '13 at 19:14
up vote 1 down vote accepted

To be able to run executables from the current directory you need to add . to your PATH environment variable. This can be done by running PATH=$PATH:. within the shell or adding export PATH=$PATH:. to your ~/.zshrc.

The other alternative is to prefix the commands you wish to run with ./ making your command

~ Desktop: gcc test.c -o test ; ./test ;

share|improve this answer
Including . in your PATH is generally considered a very bad idea. That can lead to commands behaving very differently depending on the directory which you were in when you ran the command. It can also lead to mistakenly running malicious code that is in your current directory (such as a directory which you just unpacked from a download). Getting used to using the leading ./ is a much better way to go. – qqx Jul 6 '13 at 13:05

Not the answer you're looking for? Browse other questions tagged .