Free Hosting Online for WorkStations

< Previous | Contents | Next >

Examining The Environment

To see what is stored in the environment, we can use either the set builtin in bash or the printenv program. The set command will show both the shell and environment variables, while printenv will only display the latter. Since the list of environment contents will be fairly long, it is best to pipe the output of either command into less:


[me@linuxbox ~]$ printenv | less

[me@linuxbox ~]$ printenv | less


Doing so, we should get something that looks like this:



KDE_MULTIHEAD=false SSH_AGENT_PID=6666

HOSTNAME=linuxbox

GPG_AGENT_INFO=/tmp/gpg-PdOt7g/S.gpg-agent:6689:1 SHELL=/bin/bash

TERM=xterm XDG_MENU_PREFIX=kde- HISTSIZE=1000

XDG_SESSION_COOKIE=6d7b05c65846c3eaf3101b0046bd2b00- 1208521990.996705-1177056199

GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/me/.gtkrc- 2.0:/home/me/.kde/share/config/gtkrc-2.0 GTK_RC_FILES=/etc/gtk/gtkrc:/home/me/.gtkrc:/home/me/.kde/share/confi g/gtkrc

GS_LIB=/home/me/.fonts WINDOWID=29360136

QTDIR=/usr/lib/qt-3.3 QTINC=/usr/lib/qt-3.3/include KDE_FULL_SESSION=true

USER=me LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01

:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe

:

KDE_MULTIHEAD=false SSH_AGENT_PID=6666

HOSTNAME=linuxbox

GPG_AGENT_INFO=/tmp/gpg-PdOt7g/S.gpg-agent:6689:1 SHELL=/bin/bash

TERM=xterm XDG_MENU_PREFIX=kde- HISTSIZE=1000

XDG_SESSION_COOKIE=6d7b05c65846c3eaf3101b0046bd2b00- 1208521990.996705-1177056199

GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/me/.gtkrc- 2.0:/home/me/.kde/share/config/gtkrc-2.0 GTK_RC_FILES=/etc/gtk/gtkrc:/home/me/.gtkrc:/home/me/.kde/share/confi g/gtkrc

GS_LIB=/home/me/.fonts WINDOWID=29360136

QTDIR=/usr/lib/qt-3.3 QTINC=/usr/lib/qt-3.3/include KDE_FULL_SESSION=true

USER=me LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01

:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe

:


What we see is a list of environment variables and their values. For example, we see a variable called USER, which contains the value “me”. The printenv command can also list the value of a specific variable:



[me@linuxbox ~]$ printenv USER

me

[me@linuxbox ~]$ printenv USER

me


The set command, when used without options or arguments, will display both the shell and environment variables, as well as any defined shell functions. Unlike printenv, its output is courteously sorted in alphabetical order:



[me@linuxbox ~]$ set | less

[me@linuxbox ~]$ set | less


It is also possible to view the contents of a variable using the echo command, like this:


[me@linuxbox ~]$ echo $HOME

/home/me

[me@linuxbox ~]$ echo $HOME

/home/me


One element of the environment that neither set nor printenv displays is aliases. To see them, enter the alias command without arguments:


[me@linuxbox ~]$ alias

alias l.='ls -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty'

alias vi='vim'

alias which='alias | /usr/bin/which --tty-only --read-alias --show- dot --show-tilde'

[me@linuxbox ~]$ alias

alias l.='ls -d .* --color=tty' alias ll='ls -l --color=tty' alias ls='ls --color=tty'

alias vi='vim'

alias which='alias | /usr/bin/which --tty-only --read-alias --show- dot --show-tilde'


Top OS Cloud Computing at OnWorks: