Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Linux Command Line Chapter 27

Similar presentations


Presentation on theme: "The Linux Command Line Chapter 27"— Presentation transcript:

1 The Linux Command Line Chapter 27
Flow Control: Branching with if Prepared by Dr. Reyes, New York City College of Technology

2 Branching with if if – a statement that allows you to evaluate a condition and branch based on the results Syntax Example

3 Exit Status Exit Status – integer value returned by a command when it terminates execution Range from Value of 0 indicates success Values indicates error or failure Man pages explain what each exit status means for a command $? – parameter used to examined the exit status of the last command executed

4 Test and Expressions An if statement will test an expression
You may use the keyword test or enclose the expression within [ ] test expression [ expression ] When using [ expression ] you must leave a space after opening the first bracket and another space before closing the last bracket [expression] may give unexpected results (notice the lack of spacing) A test will return zero if the expression is true, non-zero otherwise. Strange, but to be consistent with the exit status explained before

5 String Expressions

6 String Script Example

7 Integer Expressions

8 Integer Script Example

9 Other Versions of test [[ expression ]] – allows the use of regular expressions and patterns. (( arithmetic expression )) – makes arithmetic tests easier

10 Combining Expressions
Recommendation


Download ppt "The Linux Command Line Chapter 27"

Similar presentations


Ads by Google