Adding to Your zsh Path


Adding to Your zsh 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 to it as you want. For example, if you get started writing scripts (as described in Chapter 10), you might put them in a scripts subdirectory and want to add that directory to your path.

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

Code Listing 8.6. You should find your path statement in your configuration files.

jdoe@sulley ~ $ tail .zshrc # See comment at top. if [[ ! -r ${ZDOTDIR:-$HOME}/  .zshrc ]];then           if  [[ -f /usr/share/zsh/$ZSH_VERSION/  zshrc_default ]];then      source /usr/share/zsh/$ZSH_VERSION/       zshrc_default           fi fi PATH=/bin:/usr/bin:/opt/bin jdoe@sulley ~ $ 

To Change Your zsh path:

1.

more ~/.zshenv ~/.zprofile ~/.zshrc

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.6 shows, it will look something like PATH=/bin:/usr/bin:/opt/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 .zshrc .zshrc_backup 




Make a backup of the file containing the path statement so that you can recover the file when problems or errors occur. See Chapter 2 if you need more information on copying files.

3.

vi .zshrc

Use your favorite editor to open up the file whose path you want to change.

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.1).

Figure 8.1. You add or modify a zsh 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.7.)

Code Listing 8.7. Test out your edits to the configuration files.

jdoe@sulley ~ $ su - jdoe Password: jdoe@sulley ~ $ echo $PATH/bin:  /usr/bin:/opt/bin:/home/jdoe/scripts/ jdoe@sulley ~ $ 

Tip

  • 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 different program from the one you expect.





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