Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.