IBM Internal Use - December 9, 2021 1
IBM Internal Use - December 9, 2021 1
Introductions
Your name
Job role
Session objectives
Housekeeping
Breaks
Washrooms
Transportation/parking
Participation
Questions
Going to Insert mode and typing the shell Program in the vi Editor:
Quoting
Quote can be “ “ or ‘ ‘ or ` `
Example of Usage:
Without Quotes:
$ echo * <Enter>
abc.txt s.sh test.c dir1
With Quotes:
$ echo “*” <Enter>
*
$ ls -l | wc -l <Enter>
Useread.sh
Output of Useread.sh
$sh useread.sh <Enter>
String Matching and Displaying using read.
Enter the string to be found out:
IBM
Enter the File from which the string is to be found out:
profile.txt
Now Searching for IBM from the file profile.txt
My company name is IBM.
The Required Data is as above.
Thank You.
PATH.
HOME.
SHELL.
PS1.
LOGNAME.
TERM.
Command Substitution
$ echo “The number of files present in current directory are: `ls|wc –l`”
The number of files present in current directory are: 3
exit
exit 1
exit 2
Return value of any command is called the exit status of that command.
Examples:
$ expr 9 – 6 <Enter>
3
$ i = 3 <Enter>
$ i = `expr $i + 2` <Enter>
$ echo “The New value of i is: $i <Enter>
5
-eq : Equal to
string1 < string2 : Tests for the case that string2 is alphabetically after string1
if Statements : Example
ifexmpl.sh:
echo “Illustration of if Statements.”
if grep “IDP” profile.txt
then
echo “The Required Data is Obtained.”
else
echo “The Required Data is Not Obtained.”
echo “Better Luck Next Time.”
fi
$ sh ifexmpl.sh <Enter>
Illustration of if Statements.
The Required Data is Not Obtained.
Better Luck Next Time.
Case structure
Syntax
case “$var” in
opt1) <statement(s)> ;;
opt2) <statement(s)> ;;
opt3) <statement(s)> ;;
…
*) <statement(s)> ;;
esac
while loop
Syntax
while test <expression>
do
<set of statement(s)>
done
until loop
Syntax
for loop
Syntax
for iterates over a list of items, and assigns the list of items
one by one to the variable, and executes the block for
each assignment. for loop terminates when it has iterated
over all the items in the list.