[go: up one dir, main page]

0% found this document useful (0 votes)
29 views4 pages

OS Lab - Experiment No.8

The document discusses various environment variables like HOME, PATH, USER, SHELL, MAILTO, LOGNAME, PS1, PS2. It explains what each variable is used for and provides examples of how to customize them. Common uses and default settings on different operating systems are also covered.

Uploaded by

Ex Trod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views4 pages

OS Lab - Experiment No.8

The document discusses various environment variables like HOME, PATH, USER, SHELL, MAILTO, LOGNAME, PS1, PS2. It explains what each variable is used for and provides examples of how to customize them. Common uses and default settings on different operating systems are also covered.

Uploaded by

Ex Trod
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name :- Shreeom Uday Karde

Roll No :- 2201905

PRN No. :- 2030403246004

Subject :- OS Lab

EXPERIMENT NO:08

AIM: Write a note on the environment variables and demonstrate their use.
Customize the environment variables: HOME, PATH, USER, SHELL,
MAILTO, LOGNAME, PS1, PS2

THEORY:
An environment variable is a setting normally inherited or declared when a shell
is started. You can use shells to set variables; the syntax varies but Bourne
shells use:SSS
$ VARNAME="new value"
$ export VARNAME or
$ export VARNAME="new value"
Each program started from that shell will have VARNAME set to new value. The names of
environment variables are case-sensitive; by convention they are uppercase.

A shell variable is like an environment variable, except that it is not exported to


new programs started from that shell. (You could export it, but normally you just
write a shell initialisation script to set it in each shell.)

HOME
The home directory of the user. Most programs use this shell variable to find your home, thus
you can set this variable to override the setting in /etc/passwd for your home directory. This
way, you can start programs that put dotfiles or other files in a different directory than your
usual home directory.

In most shells, ~ refers to your home directory. In C shell, and some more recent versions of
Bourne shell, ~tux always refers to the home directory of user tux as specified in
/etc/passwd, while ~ (without a username after it) always refers to the value of HOME, even if
it differs from your home directory in /etc/passwd.
1

LOGNAME
The name of the user. This is an easy way for a user to get own username.
However, programs must not trust this variable because it can be set to an arbitrary value.Both
LOGNAME and USER should be set to the username.
Examples:
LOGNAME=Robin
LOGNAME=Robin
PATH
A space or colon separated list of directories in which the shell searches for executables when a
command is run without an absolute path. For example ls doesn't have an absolute path, but
/bin/ls does).

Some systems set PATH using the system shell initialization files, such as /etc/profile for
Bourne shells. Some systems set PATH before this as part of the login procedure, for example
in /etc/login.conf for OpenBSD systems. For example, a Linux box could set the PATH at login,
then add /usr/X11R6/bin to the path using /etc/profile, then add
/home/ambler/bin to the path
using ~/.bash_profile.

The system boot scripts also set PATH. On some Linux boxes, the first command to set the path
would seem to be in /etc/rc.d/rc.sysinit, which is one of the shell scripts invoked by the init
process (inittab).
Examples:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/puffy/bin
If this PATH is set and you type the shell command
$ uname -r

then the shell searches for the "uname" executable program. First it searches in
/bin, then /sbin, then /usr/bin. If /bin/uname is an executable (which it should be),
then the shell stops searching and runs it. If /home/puffy/bin/uname also is
executable, it is not run, because the search never reached that directory.
In most cases, you only append to the PATH shell variable before exporting it to the PATH
environment variable. To delete a directory from your search path, you must reassign the entire
PATH variable to a new, shorter string, and often this takes a great deal of typing or some cut
and paste operations

PS1
This is a shell variable, not normally exported as an environment variable.
The bash and public domain ksh shells use this as the prompt string.
2

Things that can be put in the prompt string include \h (hostname), \u (username), \w (absolute
pathname of working directory), \W (name of working directory w/o path), \d (date), \t (time).
On some Red Hat boxes, the primary prompt string is set in the /etc/bashrc file. The prompt is
also set in /etc/profile, but the setting in bashrc seems to take precedence. A ~/.bashrc file runs
/etc/bashrc, which sets the prompt. Because every instance of "bash" runs ~/.bashrc, the
prompt also appears in X sessions started from a display manager such as "xdm".
On some Slackware boxes, the command line prompt is set in /etc/profile.
The xterm and rxvt prompts are different. The prompt is not set for X sessions, but it would be
if you write a ~/.bashrc to do that. Prompts are shell variables set from shell initialisation
scripts. They are not xterm settings set by X resources such as /usr/X11R6/lib/X11/app-
defaults/XTerm.

PS2
This is a Primary shell variable, not normally exported as an environment
variable.
The bash and public domain ksh shells use this as a secondary prompt string

SHELL
All Unix shells are similar, but they have different features. If you are beginning,
and you are not aware of the differences between shells, then you probably want
to start with a Bourne-compatible, POSIX (Portable Operating System
Interface)compatible shell such as bash or ksh.
Bourne-compatible shells:
•sh is the original Bourne shell. On many non-Linux systems, this is an old shell without the
POSIX features. Thus bash and ksh (or even csh and tcsh) are better choices than sh. On some
systems though, sh is really the same as bash or ksh.
•bash is the GNU Bourne-again shell. It is mostly Bourne-compatible, mostly
POSIX-compatible, and has other useful extensions. It is the default on most Linux systems. If it
is not the default, it is probably installed on Linux, and can also be installed on non-Linux
systems.
•ksh is one of the three:o
Public domain ksh (pdksh) is Bourne-compatible [1] and mostly POSIX compatible.o AT&T ksh
was a commercial shell. It has all of the features of pdksh, plus the ksh93 version has several
interesting extensions, different from bash. It is licensed under an open source license since
2005; Mac OS X 10.4
includes it.omksh is the MirBSD enhanced version of the Public Domain Korn shell
(pdksh)
•ash, the Almquist shell, is a POSIX compliant shell that is much smaller than bash. It is the
default shell in multiple BSD variants. Its variant Debian
3

Almquist shell (dash) is the default shell in Debian and Ubuntu Linux
distributions for execution of shell scripts as opposed to interactive use

USER
users command in Linux system is used to show the user names of users currently
logged in to the current host. It will display who is currently logged in according to FILE. If
the FILE is not specified, use /var/run/utmp. /var/log/wtmp as FILE is common.
Syntax:
users [OPTION]... [FILE]
MAILTO
Crontab (cron table) is a text file that specifies the schedule of cron jobs. There are two types of
crontab files. The system-wide crontab files and individual user crontab files.
The email notification is sent to the owner of the crontab. To overwrite the default behavior, you
can use the MAILTO environment variable with a list (comma separated) of all the email
addresses you want to receive the email notifications.
When MAILTO is defined but empty (MAILTO=""), no mail is sent.

Conclusion:
Thus, we have successfully studied Environment variables.

You might also like