Learn C on the Mac: For OS X and iOS by David Mark & James Bucanek

Learn C on the Mac: For OS X and iOS by David Mark & James Bucanek

Author:David Mark & James Bucanek
Language: eng
Format: epub
Publisher: Apress®
Published: 2012-12-25T16:00:00+00:00


Configuring the PATH Variable

The final command is a bit tricky. You need to reconfigure the shell so it also looks in your new, private, ~/bin folder in addition to the regular ones. You’re going to do this by adding a new shell command to the .bash_profile file. Yes, that filename started with a period. Enter the following command in the shell, and be really careful with this one; the single quotes, double quotes, spaces, and punctuation have to be just so or it won’t work. Be sure you get the double quote followed by a single quote after ~/bin:

echo 'PATH="$PATH:~/bin"' >> ~/.bash_profile

The echo command is a tool that’s not much more complicated than the one you just wrote. It does nothing more than output (echo) all of its arguments to standard output—just like yours, but without any embellishment. In this case, its single argument is the shell statement PATH="$PATH:~/bin", surrounded by single quotes. This statement works something like a C assignment statement. It says that the PATH variable is to be set to the contents of the previous PATH variable plus a colon and one more path, ~/bin.

This statement gets added to a special file named .bash_profile. The >> operator took care of redirecting the echo’s output and appending it to the end of the .bash_profile file. We’ll explain all about redirection later in this chapter.

Every time the bash shell starts up, it looks for a file named .bash_profile in your home folder. If it finds it, it executes all of the statements it finds there. By adding this statement, every new shell will be configured to look for commands in your private bin folder.

Oh, and don’t bother looking for this file—you won’t find it. Names that begin with a period (so-called “dot files”) are invisible. They don’t appear in the Finder or when you list a directory using the ls command (unless you add the -a or -A switch). If you want to see the contents of this file, use the command cat ~/.bash_profile. There’s also a simple text editor you can use. The command pico ~/.bash_profile will let you interactively edit the file. Type Control+X to quit the pico editor and return the shell.

Close the Terminal window and open a new one. Remember, the .bash_profile only gets run when the shell starts, so to see your changes, you need a new shell.

If everything went according to plan, your updated PATH is all set up, as demonstrated in Figure 9-10.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.