Linux shell env
-
Upload
rahul-pola -
Category
Documents
-
view
77 -
download
0
Transcript of Linux shell env
![Page 1: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/1.jpg)
Linux Shell Environment
Content Updating Program(CUP)
On
Linux Programming
![Page 2: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/2.jpg)
Shell OverviewWhat is a Shell?
Linux shells provide a "command line" interface which allows the user to enter commands.
A shell is a program which reads and executes commands for the user.
Shell also usually provide features such as Job Control, Input/output Redirection and a Command Language for writing Shell Scripts.
The user can pick their shell (just like the applications, desktop manger, window manager, etc. on a LINUX system).
On the UMBC GL network, the default UNIX shell is tcsh -Turbo C Shell.
![Page 3: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/3.jpg)
Shell Overview Shells available include:
tcsh - Turbo C SHell
csh - C SHell
ksh - Korn SHell
bash - Bourne Again SHell
sh - SHell
Linux Default Shell
Most Linux systems (especially home installations) default to
the bash shell.
Changing Your Shell - On a Home Based System
Usually there is a command called chsh that stands for
change shell.
You have to enter your password and then the absolute path
to the new shell that you wish to use.
![Page 4: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/4.jpg)
Shell Environment Variables The bash shell uses a feature called ‘environment
variables’ to store information about the shell session
and the working environment.
USE: - Many programs and scripts uses environment
variables
- to obtain system information
- to store temporary data
- configuration information.
There are two types of environment variables
- Local Environment Variables
- Global Environment Variables
![Page 5: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/5.jpg)
Gobal Environment Variables
Global Env. Variables(GEV) are visible from
the shell session and from any child process that
the shell spawns.
Linux system sets several GEV on start of Shell.
System environment variables uses CAPITAL
letter to differ from user environment variables.
To view the GEV, use command
$ printenv
![Page 6: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/6.jpg)
GEV contiuned…..
To display a value of individual env variable
Use command
$ echo $HOME
Example of GEV available to Child process also…
![Page 7: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/7.jpg)
Local Environment Variables
LEV can be seen in the local processes in which
they are defined.
Linux system also define standard LEV for user
by default.
To view LEV use the command
$ set
(additional variables not in printenv are LEV)
![Page 8: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/8.jpg)
SETTING Env Variables
Setting LEV: Users are allowed to create local
variables that are visible within user shell process
We can assign either numerical or string value to
and environment variable using equal sign (=)
Example:
$ test=testing
$ echo $test
Standard Convention is use Lower case for LEV
and user Upper Case for GEV.
![Page 9: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/9.jpg)
SETTING GEV continued… SETTING GEV:
Create a LEV and export it to global env.
Example:
$ test=‘testing your patience’
$ echo $test
$ export test
$ bash
$ echo $test
???
![Page 10: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/10.jpg)
Removing Env. Variables Remove the Environment variable using
command – unset
Example:
$ unset test (don’t use $before variable..)
$ echo $test
Example for GEV…
![Page 11: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/11.jpg)
Default Shell Env. Variables
List of Default Variables…
![Page 12: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/12.jpg)
Important Environment Variables
HOME - your home directory.
USER and LOGNAME - your login ID.
HOSTNAME - the name of the host computer.
PWD - the current working directory.
MAIL - where your mail is located.
PATH - a list of directories in which to look for executable commands.
Certain applications and commands may communicate with the shell and reference the environment variables that it maintains. For example, it seems that frm and nfrm seem not to work if $MAIL is
not defined. frm and nfrm are commands to list the contents of your inbox without logging into pine.
![Page 13: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/13.jpg)
Setting the PATH env. variable PATH env. Variable includes all of the directories
where your applications resides.
We can add new search directories to existing
PATH environment variable without rebuild it
from scratch.
Example:
$ echo $PATH
---------------
$ PATH=$PATH:/home/user
$ echo $PATH
![Page 14: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/14.jpg)
Locating System Env. variables
When we start a bash shell by logging on to the
system, it searches several files for command,
These file are called Startup files.
Following is the order in which bash processes these
files:
/etc/profile
$HOME/.bash_profile
$HOME/.bash_login
$HOME/.profile
![Page 15: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/15.jpg)
Variable Arrays Environment variables can be used as arrays.
So it can hold multiple values.
To set list them in parentheses separated by
comma.
Example:
$ mytest=( one two three four five )
$ echo $mytest
????
$ echo ${mytest[2]}
???
![Page 16: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/16.jpg)
Aliasing Commands A helpful feature, especially for many users new to LINUX, is
the alias function.
The alias command assigns a command, possibly with many options and flags, to another name. Usually it is a shorter name or one that is easier to remember.
Setting up an alias:
The exact syntax depends on the shell that you are using. We will cover how to do it under tcsh and bash. Most other shells use a similar or identical syntax.
tcsh syntax: alias <aliased name> <original command>
bash syntax: alias <aliased name>=<original command>
Example:
$ alias dir=‘ls –l’
$dir
![Page 17: Linux shell env](https://reader031.fdocuments.in/reader031/viewer/2022020116/55a5896e1a28abd4138b4607/html5/thumbnails/17.jpg)
Thank you …