Adding or Changing Variables


After you've poked around in your environment, you might determine that you want to set a variable that's currently not available or change one to make it better meet your needs. In general, you won't randomly specify variables; you'll do it because a certain program requires a specific variable in order to run.

Variables You Can Mess With

The following table includes some of the variables you can safely change. Keep in mind that the shell itself might not use a specific variable, like NNTPSERVER, while programs running under the shell might. Sometimes shells assign default variables, while in other cases you'll have to manually set the value.

ZSH, BASH, AND KSH

CSH

DESCRIPTION

CDPATH

cdpath

Specifies the search path for directories specified by cd. This is similar to PATH.

COLUMNS

 

Specifies width of the edit window in characters.

EDITOR

 

Specifies the default editor.

ENV

 

Specifies where to look for configuration files.

HISTFILE

 

Specifies the name of the file containing the command history.

HISTFILESIZE

savehist

Specifies the maximum number of lines to keep in the history file.

HISTSIZE

history

Specifies the number of commands to keep in the command history.

HOSTFILE

 

Specifies the name of the file containing host name aliases for expansion.

IGNOREEOF

ignoreeof

Specifies that should not log out of the shell. Use IGNOREEOF=.

LINES

 

Specifies the number of lines on the screen.

MAIL

mail

Specifies the location of incoming mail so bash can notify you of mail arrival.

MAILCHECK

mail

Specifies how often (in seconds) bash checks for mail.

MAIL_WARNING

 

Specifies the message to be displayed if you have read mail but not unread mail.

noclobber

noclobber

Specifies that the shell should not overwrite an existing file when redirecting output.

PATH

path

Specifies the search path for commands, including multiple paths separated by colons.

PROMPT_COMMAND

 

Specifies the command to be run before displaying each primary prompt (does not apply to ksh).

PS1

prompt

Specifies the primary prompt.

PS2

 

Specifies the default second-level prompt.

PS3

 

Specifies the prompt for the select command in scripts.

PS4

 

Specifies the prompt used when tracing execution of a script.

TMOUT

 

Specifies time in seconds to wait for input before closing the shell.

VISUAL

 

Specifies the default visual editorusually the same as EDITOR, but referenced by different programs.



Code Listing 8.3. In the zsh, bash, and ksh shells, you can add a new environment variable by specifying the variable and its value, then exporting the variable to the system.

  [ejr@hobbes ejr]$    NNTPSERVER=news.xmission.com   [ejr@hobbes ejr]$ export NNTPSERVER   [ejr@hobbes ejr]$ echo $NNTPSERVER   news.xmission.com   [ejr@hobbes ejr]$ 

Fill in Your bash System Configuration Files

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

Fill in Your zsh System Configuration Files

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________

_________________________________________________________________________


By following the steps in this section, you can add or change environment variables for the current session. As Code Listing 8.3 shows, for example, you can specify a news server environment variable (called NNTPSERVER)that some Usenet news readers require to access the news (nntp) server.

To add or change a variable in zsh, bash, or ksh:

1.

NNTPSERVER=news.xmission.com

At the shell prompt, type the name of the variable (in this case, NNTPSERVER), followed by = and the value you want for the variable (here, news.xmission.com), as shown in Code Listing 8.3. In this step, you're setting up the variable and its value and making it available to all programs and scripts that run in the current shell session. If the value contains spaces or special characters, put the value in quotes.

2.

export NNTPSERVER

Type export followed by the name of the variable. By exporting the variable, you make it available to all programs and scripts that run in the current shell session (again, Code Listing 8.3).

Until it is exported, it is a shell variable, which will not be available to other processes that this shell starts.

3.

echo $NNTPSERVER

Optionally, type echo followed by a $ and the name of the variable to have the shell tell you what the variable is set to.

Tip

  • In bash, ksh, or zsh, save a step by typing export NNTPSERVER=news.xmission.com.


To Add or Change a Variable in csh:

1.

setenv NNTPSERVER news.xmission.com

Type setenv followed by the name of the variable, a space, and the value of the variable. In this step, you're setting up the variable and its value and making the environment variable available to all programs and scripts that run in the current shell session (Code Listing 8.4).

Code Listing 8.4. The process for the csh shell is similar to the process for the bash and ksh shells.

  xmission> setenv NNTPSERVER    news.xmission.com   xmission> echo $NNTPSERVER   news.xmission.com 

If the value contains spaces or special characters, put the value in quotes.

2.

echo $NNTPSERVERx

Optionally, type echo followed by a $ and the name of the variable to have the shell tell you what the variable is set to.

Tips

  • If you want to change or add to your variables so that the new settings exist from session to session, use the instructions for changing the environment variables in your configuration files, as described throughout the rest of this chapter.

  • Find out more about news readers in Chapter 12.





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