Bash Shell 1.0
Bash Shell 1.0
By
CHITRAKANT BANCHHOR
IT, SCOE, Pune
References
• Multi-user
Multi-
• Hierarchical file system
• Multi--tasking
Multi
• Threads
• Built--in networking
Built
• Virtual memory
UNIX Architecture
user
Hardware
ls
cp cd
who
GUI
UNIX Shells
Standard Shells
Bourne C Korn
bash tcsh
UNIX Session
How the Shell Processes Commands ?
• The shell allows you to redirect the standard output so that output goes into a
file instead.
$ who ; date
1. Execute who
2. Execute date
Command-1 | Command-2
who wc -l 3
who wc -l 3
tee command
Command - 1 file
Command - 2
save the output from a command in a file at the same time the output is piped to another command.
Command-1 | tee file-1 | command-2
Filters
Performs operations
on the inputs
Inputs from
Output
other programs
or keyboard filter result
screen
Some filters
cat grep tr
comm head sort
cut more uniq
diff paste wc
Shell Script
Shell as a command interpreter
UNIX
Shell
Interprets commands
Shell as a high-
high-level programming language
UNIX
Shell
Executes file
Contains
commands
Shell Script
UNIX
Shell
Executes file
Shell Script
Shell programming
Overview
• Features:
1. Variables
2. Input/output statements
3. Arithmetic operations
4. Branching and looping
1. Variables
I Environment Variables
II User-created Variables
User-
• These are used by the shell to store the values of command line arguments.
Special shell variables
…..
……
read
read …….
………
Shell script
…..
……
read
read echo
………
Shell script
3. Arithmetic operations using expr utility
echo $n
6.500
4. Branching and looping
if,
if else,
if elif else
case
while
until
for
test command
Numerical test
String test
File test
Numerical test
test Number1 operator Number2
operator Meaning
-eq Equal to
String test
test String1 Condition String2
Condition Meaning
Option Meaning
-s file True if the file exists and has a size greater than zero
if condition expression
then
command(s)
fi
if test condition expression
then
command(s)
fi
Or
if [ condition expression ]
then
command(s)
fi
if else statement
if condition expression
then
command(s)
else
command(s)
fi
if [ condition expression ]
then
command(s)
else
command(s)
fi
if elif statement
if condition expression
then
command(s)
elif condition expression
then
command(s)
else
command(s)
fi
if [ condition expression ]
then
command(s)
elif [ condition expression ]
then
command(s)
else
command(s)
fi
case statement
case word in
pattern1)
command(s)
;;
pattern2)
command(s)
;;
……………
patternN)
command(s)
;;
*)
esac
while loop
while condition
do
command(s)
done
As long as the condition is true, the commands between the do and the done
are executed.
until loop
until condition
do
command(s)
done
This loop continues to execute the command(s) between the do and done until
the condition is true.
for loop
function fun_name()
{
# body of the function
}