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.

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: superuser.com/questions/171909/…, superuser.com/questions/248512/… and superuser.com/questions/541749/… –  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

1 Answer 1

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
2  
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 or ask your own question.