CSC320 chapter3 Part2 - Unix/Linux commands and shell...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Unix/Linux commands and shell programming-Part 2 Original version created by: Dr. Mohamed El Bachir Menai Updated by: Dr. Safwan Qasem – Spring 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Shell logic structures The basic logic structures needed for program development are: Sequential structure Decision structures Looping structures
Background image of page 2
3 Sequential structure Sequential structure states that commands will be executed in the order in which they appear in the program The only break in this sequence comes when a branch instruction changes the flow of execution
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Decision structures The if statement is the primary decision-making control structure if (expression) simple-command or if (expression) then ... [else ...] endif
Background image of page 4
5 Decision structures, cont bash if test1; then commands1; [ elif test2; then commands2;] [ else commands3;] fi
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Decision structures, cont. Example #!/bin/csh if ($#argv != 2) then echo $0 needs two parameters! echo You are inputting $#argv parameters. else set par1 = $argv[1] set par2 = $argv[2] endif The set built-in command can be used to display all variables set in the shell
Background image of page 6
7 Decision structures, cont. Another example: #! /bin/csh # number is positive, zero or negative echo "enter a number:" set number = $< if ( $number < 0 ) then echo "negative" else if ( $number == 0 ) then echo " zero " else echo " positive " endif
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/28/2011 for the course COMPUTER S 320 taught by Professor Dr.safwanqasem during the Spring '11 term at King Saud University.

Page1 / 23

CSC320 chapter3 Part2 - Unix/Linux commands and shell...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online