Menu

UNIX TUTORIALS - Unix - Environment

Unix - Environment

ADVERTISEMENTS

PS1 and PS2 Variables:

Escape SequenceDescription
\tCurrent time, expressed as HH:MM:SS.
\dCurrent date, expressed as Weekday Month Date
\nNewline.
\sCurrent shell environment.
\WWorking directory.
\wFull path of the working directory.
\uCurrent user.s username.
\hHostname of the current machine.
\#Command number of the current command. Increases with each new command entered.
\$If the effective UID is 0 (that is, if you are logged in as root), end the prompt with the # character; otherwise, use the $.

ADVERTISEMENTS

Environment Variables:

VariableDescription
DISPLAY Contains the identifier for the display that X11 programs should use by default.
HOMEIndicates the home directory of the current user: the default argument for the cd built-in command.
IFSIndicates the Internal Field Separator that is used by the parser for word splitting after expansion.
LANGLANG expands to the default system locale; LC_ALL can be used to override this. For example, if its value is pt_BR, then the language is set to (Brazilian) Portuguese and the locale to Brazil.
LD_LIBRARY_PATH On many Unix systems with a dynamic linker, contains a colon-separated list of directories that the dynamic linker should search for shared objects when building a process image after exec, before searching in any other directories.
PATHIndicates search path for commands. It is a colon-separated list of directories in which the shell looks for commands.
PWDIndicates the current working directory as set by the cd command.
RANDOMGenerates a random integer between 0 and 32,767 each time it is referenced.
SHLVLIncrements by one each time an instance of bash is started. This variable is useful for determining whether the built-in exit command ends the current session.
TERM Refers to the display type
TZ Refers to Time zone. It can take values like GMT, AST, etc.
UIDExpands to the numeric user ID of the current user, initialized at shell startup.

ADVERTISEMENTS

$TEST="Unix Programming"
$echo $TEST
Unix Programming

$

Setting the Terminal Type:

$TERM=vt100
$

Setting the PATH:

$PATH=/bin:/usr/bin
$

$hello
hello: not found
$

PS1 and PS2 Variables:

$PS1='=>'
=>
=>
=>

=>PS1="[\u@\h \w]\$"
[root@ip-72-167-112-17 /var/www//unix]$
[root@ip-72-167-112-17 /var/www//unix]$

$ echo "this is a
> test"
this is a
test
$

$ PS2="secondary prompt->"
$ echo "this is a
secondary prompt->test"
this is a
test
$

Environment Variables:

$ echo $HOME
/root
]$ echo $DISPLAY

$ echo $TERM
xterm
$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/home/amrood/bin:/usr/local/bin
$