31.10.2016 Views

Shell Scripts

week5_loops

week5_loops

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.

31-Oct-16<br />

The While Loop<br />

SYNTAX<br />

#!/bin/sh<br />

while command<br />

do<br />

Statement(s) to be executed<br />

done<br />

if command is true<br />

a=0<br />

while [ $a –lt 10 ]<br />

do<br />

done<br />

echo $a<br />

a=`expr $a + 1 `<br />

The For Loop<br />

SYNTAX<br />

#!/bin/sh<br />

for var in word1 word2 ... wordN<br />

do<br />

done<br />

Statement(s) to be executed for<br />

every word.<br />

for var in 0 1 2 3 4 5 6 7 8 9<br />

do<br />

echo $var<br />

done<br />

2

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

Saved successfully!

Ooh no, something went wrong!