Академический Документы
Профессиональный Документы
Культура Документы
ANDHRA PRADESH
Name : A V N L Sarojini
Designation : Lecturer
Branch : Computer Engineering
Institute : A.A.N.M. & V.V.R.S.R. Poly.,
Gudlavalleru.
Year/Semester : III Semester
Subject : UNIX & C
Subject Code : CM-302
Topic : Shell Programming &
Filtering Techniques
Duration : 50 Min
Sub Topic : basics types of shell variables
CM304.12 1
Recap
CM304.12 2
Objective
On completion of this period, you would able to
know
Shell Variables
Type of Shell variables
Working with user defined variables
– Rules for framing variable name
– Shell keywords
– Reading values into shell variables.
– Displaying contents of shell variables.
– Arithmetic's in shell script
– Example Programs
CM304.12 3
What is “Shell variable”?
CM304.12 4
Type of shell Variables
CM304.12 5
Unix-defined Variables (or) System Variables
CM304.12 6
UNIX-defined Variables (or) System Variables
Contd..
CM304.12 7
User-defined Variables
CM304.12 8
User-defined Variables
<variable_name>=<value>
CM304.12 9
Rules for framing variable name
CM304.12 10
Rules for framing variable name Contd..
CM304.12 11
Shell Keywords
CM304.12 12
Following are the list of keywords
for return
CM304.12 13
Assigning Values to Variables
Example
– alpha=“hello world”
– beta=45
– dirname=“/usr/aa5”
CM304.12 14
Reading values into shell variables
The read statement is used to
– read a line of standard input
– split the line into fields of one or more strings
– assign those strings to shell variables.
Syntax:
read <var 1> <var 2> … <var n>
CM304.12 15
Reading values into shell variables
Contd..
Example:
– read num
CM304.12 16
All shell variables are string variables.
Example a=20
CM304.12 17
Using shell variables
Example:
mypath=/home/special/public_html
ls –al $mypath
CM304.12 18
Displaying contents of a variable
CM304.12 19
Displaying contents of a variable
Contd..
Example
$c=“Two Words”
$echo $c
$name=Johny age=10
$echo $name $age
$echo Name of the boy is $name age is $age
CM304.12 20
Example Program
$cat telno.sh
echo “Enter the Name”
read name
echo “Enter the Telephone Number”
read number
echo $name $number
CM304.12 21
Arithmetic's in Shell Script
CM304.12 22
Example program
$cat arith.c
a=20
b=10
echo `expr $a + $b`
echo `expr $a - $b`
echo `expr $a \* $b`
echo `expr $a / $b`
Note: The character used before expr is called grave
accent i.e., the character below the tilde sign in the
keyboard.
CM304.12 23
Summary
CM304.12 24
Quiz
CM304.12 25
Quiz
CM304.12 26
Quiz
CM304.12 27
Quiz
CM304.12 28
Quiz
CM304.12 29
Quiz
CM304.12 30
Pick up the correct option
CM304.12 31
Pick up the correct option
CM304.12 32
FAQ’s
CM304.12 33
FAQ’s
CM304.12 34