The Linux Command Line Chapter 27

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

Pearson Education, Inc. All rights reserved. 1.. Exception Handling.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 2 Flow of Control. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Learning Objectives Boolean Expressions Building, Evaluating.
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
CS 497C – Introduction to UNIX Lecture 33: - Shell Programming Chin-Chih Chang
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
JavaScript, Third Edition
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Chapter 2 Basic SQL SELECT Statements
Agenda Control Flow Statements Purpose test statement if / elif / else Statements for loops while vs. until statements case statement break vs. continue.
Introduction to Shell Script Programming
Shell Programming. Introducing UNIX Shells  Shell is also a programming language and provides various features like variables, branching, looping and.
Fundamentals of Python: First Programs
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
ITIP © Ron Poet Lecture 12 1 Finding Out About Objects.
Chapter 05 (Part III) Control Statements: Part II.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Bordoloi and Bock Control Structures: Iterative Control.
EMT 2390L Lecture 9 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Introduction to Computer Programming
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
PROGRAMMING THE BASH SHELL PART III by İlker Korkmaz and Kaya Oğuz
String and Lists Dr. José M. Reyes Álamo.
Shell Control Structures
Chapter 4 Repetition Statements (loops)
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
Chapter 2 - Introduction to C Programming
Chapter 3 Branching Statements
Chapter 3 Loops Section 3.3 Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Lecture 9 Shell Programming – Command substitution
The Linux Command Line Chapter 14
Chapter 2 - Introduction to C Programming
Agenda Control Flow Statements Purpose test statement
The Linux Command Line Chapter 29
Control Structures: if Conditional
The Linux Command Line Chapter 10
The Linux Command Line Chapter 7
The Linux Command Line Chapter 27
Control Structures: for & while Loops
The Linux Command Line Chapter 11
The Linux Command Line Chapter 3
The Linux Command Line Chapter 26
The Linux Command Line Chapter 28
String and Lists Dr. José M. Reyes Álamo.
CS139 October 11, 2004.
The Linux Command Line Chapter 17
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
The Linux Command Line Chapter 25
Linux Shell Script Programming
EPSII 59:006 Spring 2004.
The Linux Command Line Chapter 14
Shell Control Structures
Shell Control Structures
CST8177 Scripting 2: What?.
Review.
The Linux Command Line Chapter 5
Review The Unix Shells Graham Glass and King Ables,
The Linux Command Line Chapter 3
The Linux Command Line Chapter 11
The Linux Command Line Chapter 26
Presentation transcript:

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

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

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

Test and Expressions An if statement will test an expression You may use the keyword test or enclose the expression within brackets [ ] 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 spaces) A test will return zero if the expression evaluates to true, non-zero otherwise. Strange, but to be consistent with the exit status explained before

String Expressions

String Script Example

Integer Expressions

Integer Script Example

Other Versions of test [[ expression ]] – allows the use of regular expressions and patterns, still need spaces. (( arithmetic expression )) – makes arithmetic tests easier, does not require spaces.

Combining Expressions Recommendation