View Single Post

nabl's Avatar
Member Since: Dec 13, 2007
Location: United States of America
Posts: 256
nabl has a spectacular aura about
Mac Specs: 2.1GHz MacBook with 4GB RAM, Mac OS X 10.6, iLife and iWork 09

nabl is offline
$PATH is a variable in the Terminal that tell the computer which directories contain programs; that is, when you type a command such as ls at the command-line, ls is the name of a program in one of the locations specified by $PATH.

To figure out where a binary is, you can use the which command. For example, typing which ls should return something like /bin/ls, which means that if you were to navigate to the /bin directory, you'd see the ls program within.

To see the list of locations that are currently set for $PATH, you can type echo $PATH at the command-line. It will return a list of directories (folders) separated by colons; these are the locations that will be checked in when you type a command name. In your case, you could copy those programs to a place like /usr/bin by typing the following command:
sudo cp program_name /usr/bin/
You'll need to type in your administrator password for the command to work because /usr/bin is a system directory (you get permission to move files there with the sudo command). This will copy the program you choose to that folder, at which point you can simply type its name and press Return to run it.

Alternatively, if you don't want to mess with using the sudo command (which you should always be extremely careful with), you can add a new directory to your $PATH, from which you'll be able to run commands in the future. To do this, you need to edit either .bashrc or .bash_profile. For example, type
open -a TextEdit ~/.bash_profile
This will open your Bash profile (think of it as command-line preferences) in TextEdit, where you can add this line to the bottom:
export PATH=$PATH:/new/directory
where /new/directory is the folder you want to add to your $PATH. For example, if you make a folder in your Home directory called Programs, you could run the command
export PATH=$PATH:/Users/your_username/Programs
and any binaries you put in that folder will run when you type their names at the command prompt.

Once you add that line to the file, save it and close it. For the change to take effect, type
source ~/.bash_profile
This command tells the computer to look at .bash_profile and update any changes, which will in this case update your $PATH. To make sure it took effect, you can type echo $PATH again, and you should see the same list you saw before with your new location at the end. Then, when you add any programs to the folder you chose (in this example, /Users/your_username/Programs), you'll simply be able to type their name at the command prompt and press Return to run them.

There's one final thing worth saying. If you only want to run a program once, you can navigate to the directory containing it and type the command name preceded by a period and a slash (./) to run the program regardless of whether the containing folder is in your $PATH or not. As an example, if your cuffs program is in your Downloads folder, typing the following two commands would run it a single time:
cd ~/Downloads

Hopefully that little overview will help you out. If you want to find out more, search for "bash path" on a search engine and you should get relevant results.
QUOTE Thanks