Adding to Your bash Path


Adding to Your bash Path

One of the most useful changes you can make to your environment is adding to the default path, which is determined by the path statement. The path statement tells the shell where to look for commands, scripts, and programs. That is, if you issue a command, the path statement tells the system to look for that command in each of the named directories in a specific order.

Be sure not to remove anything from your path unless you really know what you're doing, but feel free to add as many additional directories as you want to it.

As the following steps show, you change your bash path by first identifying where your path statement is located, then editing the file that contains it (Code Listing 8.11).

Code Listing 8.11. Your first step is finding out the location of your path statement(s).

[ejr@hobbes ejr]$ more ~/.bash_profile  ~/.bashrc :::::::::::::: /home/ejr/.bash_profile :::::::::::::: # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then     . ~/.bashrc fi PATH=/bin:/usr/bin:/usr/local/bin # User-specific environment and startup programs PATH=$PATH:/usr/local/games ENV=$HOME/.bashrc USERNAME="" export USERNAME ENV PATH -More-(Next file: /home/ejr/.bashrc) 

To Change Your bash Path:

1.

more ~/.bash_profile ~/.bashrc

To begin, view your configuration files (just the ones you can edit) in the order they're executed.

Look through your system configuration files for a path statement. As Code Listing 8.11 shows, it'll look something like PATH=/bin:/usr/bin:/usr/local/bin. If you have more than one path statement, find the last one executed.

Remember that different systems will have different configurations, so you might need to do a little digging to find your personal path statement(s).

2.

cp .bash_profile .bash_profile_backup

Make a backup of the file containing the path statement so that you can recover if you make mistakes. See Chapter 2 if you need more information on copying files.

3.

vi .bash_profile

Use your favorite editor to open up the file in which you'll be changing the path.

4.

PATH=$PATH:$HOME/scripts

Add a new path statement immediately below the last path statement. In this example, PATH is set to its current value ($PATH) plus the directory ($HOME/scripts) you wish to append to your path." (Figure 8.3).

Figure 8.3. You add or modify a bash path statement in your editor.


5.

Save the file and exit from your editor. Refer to Chapter 4 for help if you need it.

6.

su - yourid

As you learned back in Chapter 3, this command starts a new login shell so you can test your changes before logging out.

7.

echo $PATH

Display the current path environment variable. This should include the addition you just made. It's there, right? (See Code Listing 8.12.)

Code Listing 8.12. Using echo, you can verify that your new path statement exists.

[ejr@hobbes ejr]$ echo $PATH /bin:/usr/bin:/usr/local/bin:/usr/bin/X11 :/ usr/X11R6/bin:/usr/local/games:/home/ejr/ bin [ejr@hobbes ejr]$ 

Tips

  • If you look through the path statements in your various configuration files, you might find a path statement that includes just a . (dot). For example, you might see something like PATH=/usr/bin:/usr/ local/bin:.:. The . adds your current directory, whatever it might be, to your path. Keep in mind, though, that it's often safer not to have the current directory in the path so you don't unintentionally run a program that isn't the one you expect to run (because there's an executable file by the same name in your current directory).

  • You can use grep to make it easier to find the configuration files that set your path. grep PATH ~/.bash* ~/.profile is a good way to start, and grep PATH /etc/* is another goodie.

  • Your system configuration files will be much less confusing later on if you keep all related changes together. Therefore, you should keep the path statements together, rather than just plug an entirely random PATH statement into your configuration files.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net