Module 13: Shell Scripts in UNIX - E-Courses
Module 13: Shell Scripts in UNIX - E-Courses Module 13: Shell Scripts in UNIX - E-Courses
Operating Systems Prof. P. C. P. Bhat Indian Institute of Science Bangalore Operating Systems/Shell Scripts in UNIX Lecture Notes a=`expr $b + 2` echo $a echo on multiplying two we get a=`expr $b \* 2` /* Note the back slash preceding star */ # We shall see the reason for using back slash before star in the next example echo $a test $a -gt 100 $? test $a -lt 100 $? test $a -eq 6 $? test $a = 6 $? test $a -le 6 $? test $a -ge 6 $? test $a = 5 $? if (test $a = 5) then echo "found equal to 5" else echo "found not equal to 5" fi test $a = 6 if (test $a = 6) then echo "the previous test was successful" fi ----------------------------------------------------------------------file sh 10.file Now we shall use some regular expressions commonly used with file names. PCP Bhatt/IISc, Bangalore M13/V1/June 04/14
Operating Systems Prof. P. C. P. Bhat Indian Institute of Science Bangalore Operating Systems/Shell Scripts in UNIX Lecture Notes # file sh_10.file # in this program we identify directories in the current directory echo "listing all the directories first" for i in * do if test -d $i then echo "$i is a directory" fi done echo "Now listing the files" for i in * do if test -f $i then echo "$i is a file" fi done echo "finally the shell files are" ls | grep sh_ ----------------------------------------------------------------------file sh 11.file # file sh_11.file # In this file we learn about the trap command. We will first # create many files with different names. Later we will remove # some of these by explicitly trapping touch rmf1 touch keep1 touch rmf2 touch rmf3 touch keep2 touch rmf4 PCP Bhatt/IISc, Bangalore M13/V1/June 04/15
- Page 1 and 2: Operating Systems Prof. P. C. P. Bh
- Page 3 and 4: Operating Systems Prof. P. C. P. Bh
- Page 5 and 6: Operating Systems Prof. P. C. P. Bh
- Page 7 and 8: Operating Systems Prof. P. C. P. Bh
- Page 9 and 10: Operating Systems Prof. P. C. P. Bh
- Page 11 and 12: Operating Systems Prof. P. C. P. Bh
- Page 13: Operating Systems Prof. P. C. P. Bh
- Page 17 and 18: Operating Systems Prof. P. C. P. Bh
- Page 19: Operating Systems Prof. P. C. P. Bh
Operat<strong>in</strong>g Systems Prof. P. C. P. Bhat<br />
Indian Institute of Science Bangalore<br />
Operat<strong>in</strong>g Systems/<strong>Shell</strong> <strong>Scripts</strong> <strong>in</strong> <strong>UNIX</strong> Lecture Notes<br />
a=`expr $b + 2`<br />
echo $a<br />
echo on multiply<strong>in</strong>g two we get<br />
a=`expr $b \* 2` /* Note the back slash preced<strong>in</strong>g star */<br />
# We shall see the reason for us<strong>in</strong>g back slash before star <strong>in</strong> the next example<br />
echo $a<br />
test $a -gt 100<br />
$?<br />
test $a -lt 100<br />
$?<br />
test $a -eq 6<br />
$?<br />
test $a = 6<br />
$?<br />
test $a -le 6<br />
$?<br />
test $a -ge 6<br />
$?<br />
test $a = 5<br />
$?<br />
if (test $a = 5)<br />
then echo "found equal to 5"<br />
else echo "found not equal to 5"<br />
fi<br />
test $a = 6<br />
if (test $a = 6)<br />
then echo "the previous test was successful"<br />
fi<br />
----------------------------------------------------------------------file<br />
sh 10.file Now we shall use some regular expressions commonly used with file<br />
names.<br />
PCP Bhatt/IISc, Bangalore M<strong>13</strong>/V1/June 04/14