Lab 8
This presentation is the property of its rightful owner.
Sponsored Links
1 / 16

Lab 8 PowerPoint PPT Presentation


  • 109 Views
  • Uploaded on
  • Presentation posted in: General

Lab 8. Shell Script. Reference: Linux Shell Scripting Tutorial v1.05r3 A Beginner's handbook http://www.freeos.com/guides/lsst/index.html. if condition. if condition which is used for decision making in shell script, If given condition is true then command1 is executed . Syntax :

Download Presentation

Lab 8

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Lab 8

Lab 8

Shell Script

Reference:

Linux Shell Scripting Tutorial v1.05r3A Beginner's handbook

http://www.freeos.com/guides/lsst/index.html


If condition

if condition

if condition which is used for decision making in shell script, If given condition is true then command1 is executed.

Syntax:

if condition

then

command1...

fi


If condition1

if condition


Test command or expr

test command or [ expr ]

- -True  return zero(0)

Is used to see if an expression is true

- -Falsereturns nonzero

Syntax:test expression OR [ expression ]

Run it as follows:


Test command or expr1

test command or [ expr ]


Test command or expr2

test command or [ expr ]


Test command or expr3

test command or [ expr ]


If else fi

if …else…fi

If given condition is true then command1 is executed otherwise command2 is executed.

Syntax:

if condition

then

condition

else

if condition is not true then execute all commands up to fi

fi


If else fi1

if …else…fi


Lab 8

Special shell variables $0…$9

Positional parameters or command line arguments

myscript $0

foo $1

Bar$2

$#tells you how many parameter your script was given


If else fi2

if …else…fi

Syntax:

if condition

Then

if condition

then

.....

..

do this

else

....

..

do this

fi

else

...

.....

do this

fi


Nested if else fi

Nested if-else-fi


Multilevel if then else

Multilevel if-then-else

Syntax:

if condition

then

condition is zero (true - 0)

execute all commands up to elif statement

elif condition1 then

condition1 is zero (true - 0)

execute all commands up to elif statement

elif condition2

then

condition2 is zero (true - 0)

execute all commands up to elif statement

else

None of the above condtion,condtion1,condtion2 are true

(i.e. all of the above nonzero or false)

execute all commands up to fi

fi


For loop

for Loop

Syntax:

for { variable name } in { list }

Do

execute one for each item in the list until the list is not finished (And repeat all statement between do and done)

done


For loop1

for Loop


  • Login