Module 13: Shell Scripts in UNIX - E-Courses
Module 13: Shell Scripts in UNIX - E-Courses
Module 13: Shell Scripts in UNIX - E-Courses
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
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 />
echo Suppose we now use "?" option. Then we shall get an error message<br />
echo ${param?error}<br />
-----------------------------------------------------------------------<br />
# file sh_2a.file<br />
# This is to f<strong>in</strong>d out if a certa<strong>in</strong> parameter has been def<strong>in</strong>ed.<br />
echo param is not def<strong>in</strong>ed so we should get a null value for param<br />
echo ${param}<br />
# echo param is not def<strong>in</strong>ed with "?" option we get the error message<br />
# echo ${param?error}<br />
echo param is not def<strong>in</strong>ed with "-" option we get the quoted message<br />
echo ${param-'user generated quoted message'}<br />
-----------------------------------------------------------------------<br />
# file sh_2b.file<br />
# This is to f<strong>in</strong>d out if a certa<strong>in</strong> parameter has been def<strong>in</strong>ed.<br />
echo param is not def<strong>in</strong>ed so we should get a null value for param<br />
echo ${param}<br />
# echo param is not def<strong>in</strong>ed with "?" option we get the error message<br />
# echo ${param?error}<br />
echo param is not def<strong>in</strong>ed with "=" option we get the quoted message<br />
echo ${param='user generated quoted message'}<br />
file sh_3.file: Now we shall see a few scripts that use a text with three k<strong>in</strong>ds of quotes -<br />
the double quotes, the s<strong>in</strong>gle forward quote and the s<strong>in</strong>gle backward quote. As the<br />
examples <strong>in</strong> files sh 3, sh 3a and sh 3b show, the double quotes evaluates a str<strong>in</strong>g with<strong>in</strong><br />
it as it is. The back quotes result <strong>in</strong> substitut<strong>in</strong>g the value of shell variables and we may<br />
use variables with a $ sign pre-fixed if we wish to have the str<strong>in</strong>g substituted by its value.<br />
We show the use of back quotes <strong>in</strong> this script <strong>in</strong> a variety of contexts.<br />
# file sh_3.file<br />
echo the next l<strong>in</strong>e shows command substitution with<strong>in</strong> back quotes<br />
echo I am `whoami` /* every th<strong>in</strong>g<strong>in</strong> back quotes is evaluated */<br />
echo I am 'whoami' /* noth<strong>in</strong>g <strong>in</strong> back quotes is evaluated */<br />
echo "I am us<strong>in</strong>g $SHELL" /* Variables evaluated <strong>in</strong> double quotes */<br />
PCP Bhatt/IISc, Bangalore M<strong>13</strong>/V1/June 04/7