Discovering Your Current Environment


A good first step in changing your environment is determining what environment you have. Using the steps in this section, you can discover which environment and shell variables are currently setincluding ones set in the configuration files as well as ones you've set for the current session (Code Listings 8.1 and 8.2).

Code Listing 8.1. You can find out which variables exist in the zsh, bash, or ksh shells with set.

  [ejr@hobbes ejr]$ set   BASH=/bin/bash   BASH_VERSION=1.14.7(1)   COLUMNS=80   ENV=/home/ejr/.bashrc   EUID=500   HISTFILE=/home/ejr/.bash_history   HISTFILESIZE=1000   HISTSIZE=1000   HOME=/home/ejr   HOSTNAME=hobbes.raycomm.com   HOSTTYPE=i386   IFS=   LINES=24   LOGNAME=ejr   MAIL=/var/spool/mail/ejr   MAILCHECK=60   OLDPWD=/home/ejr/src/rpm-2.5.1   OPTERR=1   OPTIND=1   OSTYPE=Linux   PATH=/usr/local/bin:/bin:/usr/bin:/usr/    X11R6/bin:/home/ejr/bin   PPID=1943   PS1=[\u@\h \W]\$   PS2=>   PS4=+   PWD=/home/ejr   SHELL=/bin/bash   SHLVL=3   TERM=vt220   UID=500   USER=ejr   USERNAME=   _=cd   [ejr@hobbes ejr]$ 

As you're going through these steps, you might check out the sidebar Variables in Your Environment You Shouldn't Touch in this section for a list of variables you should leave alone. Then, in the next section, check out Variables You Can Mess With to find ones you can change.

To show your current environment in zsh, bash, or ksh:

  • set

    At the shell prompt, type set. You'll see a list of the current environment and shell variables, as shown in Code Listing 8.1. Some of the variables may look familiar to you (such as the ones showing your shell or user name), while others are likely to be more cryptic (such as the line showing the last command you ran, in this case, _=cd).

To show your current environment in csh:

  • setenv

    At the shell prompt, type setenv. As Code Listing 8.2 shows, the preconfigured variables will closely resemble the environment variables that bash or ksh offer.

Code Listing 8.2. Or, use setenv to find out which variables exist in the csh shell at the c-shore.

xmission> setenv HOME=/home/users/e/ejray PATH=/usr/local/bin:/usr/local/bin/X11:/  usr/openwin/bin:/usr/bin:/usr/ucb:/usr/. LOGNAME=ejray HZ=100 TERM=vt100 TZ=MST7MDT SHELL=/usr/bin/csh MAIL=/var/mail/ejray PWD=/home/users/e/ejray USER=ejray EDITOR=pico -t OPENWINHOME=/usr/openwin MANPATH=/usr/man:/usr/local/man:/usr/  openwin/man LD_LIBRARY_PATH=/usr/local/lib:/usr/  openwin/lib PAGER=more xmission> 

Tips

  • If you do as we often do and try to use show to show the environment variables ("showing" the variables seems logical, right?), you might get a weird question about the standard mail directories and the MH mailer. Just press to return to your shell prompt.

  • If the list of environment variables is long, you can pipe set or setenv to more so that you can read the variables one screen at a time. Try set | sort | more or setenv | sort | more. See Chapter 1 for a reminder about piping commands.


Variables in Your Environment You Shouldn't Touch

Before you go running off and changing your environment, note that there are some things you should really leave alone. These variables that the shell automatically sets affect how your Unix system works (or doesn't work, if you try to change some of these variables!). Some of these cannot be changed, but some can, with unpredictable results. When in doubt, don't. See the sidebar Variables You Can Mess With in the following section for a list of variables you can change.

ZSH, BASH, AND KSH

CSH

DESCRIPTION

HISTCMD

 

Keeps track of the number of the current command from the history.

HOSTTYPE

 

Holds a string describing the type of hardware on which the shell is running.

IFS

 

Specifies the characters that indicate the beginning or end of words.

LINENO

 

Contains the number of the current line within the shell or a shell script.

OLDPWD

 

Contains the previous working directory.

OSTYPE

 

Holds a string describing the operating system on which the shell is running.

PPID

 

Contains the process ID of the shell's parent.

PWD

cwd

Contains the current working directory.

RANDOM

 

Contains a special value to generate random numbers.

SECONDS

 

Contains the number of seconds since the shell was started.

SHELL

shell

Contains the name of the current shell.

SHLVL

 

Contains a number indicating the sub-shell level (if SHLVL is 3, two parent shells exist and you'll have to exit from three total shells to completely log out).

UID

 

Contains the userid of the current user.






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