19.03.2015 Views

Unix Tutorial

test

test

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4) juice<br />

5) appe<br />

6) all<br />

7) none<br />

#? juice<br />

Available at home<br />

#? none<br />

$<br />

You can change the prompt displayed by the select loop by altering the variable PS3 as follows:<br />

$PS3="Please make a selection => " ; export PS3<br />

$./test.sh<br />

1) tea<br />

2) cofee<br />

3) water<br />

4) juice<br />

5) appe<br />

6) all<br />

7) none<br />

Please make a selection => juice<br />

Available at home<br />

Please make a selection => none<br />

$<br />

You would use different loops based on dfferent situation. For example while loop would execute given<br />

commands until given condition remains true where as until loop would execute until a given condition becomes<br />

true.<br />

Once you have good programming practice you would start using appropriate loop based on situation. Here while<br />

and for loops are available in most of the other programming languages like C, C++ and PERL etc.<br />

Nesting Loops:<br />

All the loops support nesting concept which means you can put one loop inside another similar or different loops.<br />

This nesting can go upto unlimited number of times based on your requirement.<br />

Here is an example of nesting while loop and similar way other loops can be nested based on programming<br />

requirement:<br />

Nesting while Loops:<br />

It is possible to use a while loop as part of the body of another while loop.<br />

Syntax:<br />

while command1 ; # this is loop1, the outer loop<br />

do<br />

Statement(s) to be executed if command1 is true<br />

while command2 ; # this is loop2, the inner loop<br />

do<br />

Statement(s) to be executed if command2 is true<br />

done<br />

Statement(s) to be executed if command1 is true<br />

done<br />

TUTORIALS POINT<br />

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!