views:

27

answers:

1

I just finished writing my very first command-line tool in Objective-C, compiled it, and now I'm curious about how one would go about making it executable as a command.

For example, right now to use the program I have to type in ./filename -args into Terminal. I'd like to be able to only type in filename and execute the program.

I tried using sudo chmod a+x filename but no go.

+2  A: 
sudo cp filename /usr/local/bin/

Or add the directory containing filename into $PATH. Like as all other UNIX-derived OSs.

KennyTM
Awesome, that works. Now, how would I remove it?
Calvin L
@Calvin: `sudo rm /usr/local/bin/filename`.
KennyTM
I did that, but now when I type in "filename" anywhere it says <code>/usr/local/bin/filename: No such file or directory</code>, which leads me to believe it's still stored somewhere?
Calvin L
@Calvin: since `/usr/local/bin/filename` no longer exists, `rm` can't find it, thus telling you `/usr/local/bin/filename: No such file or directory`.
KennyTM
I know that -- I removed the file, but when I try to use the command "filename" in any directory, it tells me that there is no such file or directory rather than telling me "filename: command not found"
Calvin L
If you start a new shell you'll get command not found; the one you're using has cached the existence of the file.
Andrew McGregor
@Calvin L:If you're going to learn to program then you really also need to spend a little time learning the basics of the operating system that you are using.
Paul R
Once it's found a command, bash caches its location for faster look up next time you try to run it. Apparently, you can clear the cash with `hash -r`
JeremyP