Control Structures. CIS 118 Intro to LINUX

Similar documents
example: name1=jan name2=mike export name1 In this example, name1 is an environmental variable while name2 is a local variable.

Conditional Control Structures. Dr.T.Logeswari

Bash scripting basics

Shell programming. Introduction to Operating Systems

COMP 4/6262: Programming UNIX

Shell Start-up and Configuration Files

Scripting. More Shell Scripts. Adapted from Practical Unix and Programming Hunter College

Bash shell programming Part II Control statements

Computer Systems and Architecture

Computer Systems and Architecture

bash Execution Control COMP2101 Winter 2019

Shell Script Example. Here is a hello world shell script: $ ls -l -rwxr-xr-x 1 horner 48 Feb 19 11:50 hello* $ cat hello #!/bin/sh

A control expression must evaluate to a value that can be interpreted as true or false.

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Chapter 1 CONTROL STRUCTURES. SYS-ED/ Computer Education Techniques, Inc.

Prof. Navrati Saxena TA: R. Sachan Bharat Jyoti Ranjan

Title:[ Variables Comparison Operators If Else Statements ]

There are some string operators that can be used in the test statement to perform string comparison.

Practical 04: UNIX / LINUX Shell Programming 1

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

OPERATING SYSTEMS LAB LAB # 6. I/O Redirection and Shell Programming. Shell Programming( I/O Redirection and if-else Statement)

Bourne Shell Reference

A shell can be used in one of two ways:

CSC 2500: Unix Lab Fall 2016

Operators. Java operators are classified into three categories:

9.2 Linux Essentials Exam Objectives

Control Structures. Control Structures 3-1

Cisco IOS Shell. Finding Feature Information. Prerequisites for Cisco IOS.sh. Last Updated: December 14, 2012

Chapter 2: Functions and Control Structures

CSE 390a Lecture 6. bash scrip'ng con'nued; remote X windows; unix 'dbits

Week 6 Lesson 1: Control-Flow Statements (Continued)

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Vi & Shell Scripting

Shell script. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.

Template Language and Syntax Reference

CSE 390a Lecture 6. bash scripting continued; remote X windows; unix tidbits

Fortran 90 Two Commonly Used Statements

Lab 4: Shell scripting

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

EECS2301. Special variables. $* and 3/14/2017. Linux/Unix part 2

Shell Programming. Introduction to Linux. Peter Ruprecht Research CU Boulder

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Unix Scripts and Job Scheduling. Overview. Running a Shell Script

Spoke. Language Reference Manual* CS4118 PROGRAMMING LANGUAGES AND TRANSLATORS. William Yang Wang, Chia-che Tsai, Zhou Yu, Xin Chen 2010/11/03

Flow Control. CSC215 Lecture

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

Practice 5 Batch & Shell Programming

CS Unix Tools & Scripting

7 Control Structures, Logical Statements

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

(Refer Slide Time: 01:12)

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo

Turtle Tango (TT) Language Reference Manual

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

B E C Y. Reference Manual

Essential Skills for Bioinformatics: Unix/Linux

Test #2 October 8, 2015

28-Nov CSCI 2132 Software Development Lecture 33: Shell Scripting. 26 Shell Scripting. Faculty of Computer Science, Dalhousie University

SAS Programming Basics

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

TML Language Reference Manual

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CA4003 Compiler Construction Assignment Language Definition

Visualize ComplexCities

Програмиранев UNIX среда

Bash scripting Tutorial. Hello World Bash Shell Script. Super User Programming & Scripting 22 March 2013

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

While Statement Examples. While Statement (35.15) Until Statement (35.15) Until Statement Example

GBL Language Reference Manual

Petros: A Multi-purpose Text File Manipulation Language

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

Statements 2. a operator= b a = a operator b

Flow Control: Branches and loops

Unix Shell scripting. Dr Alun Moon 7th October Introduction. Notation. Spaces

egrapher Language Reference Manual

GAWK Language Reference Manual

DEMO A Language for Practice Implementation Comp 506, Spring 2018

The PCAT Programming Language Reference Manual

Language Reference Manual

Assignment 3, Due October 4

Relational Expressions. Boolean Expressions. Boolean Expressions. ICOM 4036 Programming Languages. Boolean Expressions

CHAD Language Reference Manual

PLT Fall Shoo. Language Reference Manual

8. Control statements

The ILOC Simulator User Documentation

Flow of Control. Chapter 3 Part 3 The Switch Statement

Preview. Review. The test, or [, command. Conditions. The test, or [, command (String Comparison) The test, or [, command (String Comparison) 2/5/2019

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

CSE 390a Lecture 6. bash scripting continued; remote X windows; unix tidbits

Lecture 5. Essential skills for bioinformatics: Unix/Linux

The Warhol Language Reference Manual

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Advanced Unix Programming Module 03 Raju Alluri spurthi.com

Desktop Command window

(Extract) JCL. MVS - OS/390 - z/os. Michel Castelein - Arcis Services 14 May

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Transcription:

Control Structures CIS 118 Intro to LINUX

Basic Control Structures

TEST The test utility, has many formats for evaluating expressions. For example, when given three arguments, will return the value true if the first and third argument hold the relation represented by the second argument, but it also has many options to test other properties of files, strings and integers. The test utility can be used by stating the keyword test which is then followed by one of its many expression formats, or the test utility can simply be called by putting the expression in square brackets. There are also compound expressions allowed in the test expression. These are built by using the -a for "and and the -o for "or". You can also use parentheses to set the order of precedence and the exclamation point! for negation. integer1 -lt,-gt, -eq, -ne, -le, -ge integer2 string1 = string2 string1!= string2 -z string (string is zero length) -s string (string is not zero length) -f filename (file exists) d dirname (directory exists) -r, -w, -x filename (tests for perimissions on a file)

IF Statements IF-THEN The sequence of statements is executed only if the condition is true. If the condition is false or null, the IF statement does nothing. In either case, control passes to the next statement. The simplest form of IF statement associates a condition with a sequence of statements enclosed by the keywords THEN and FI as follows: if [ condition ] then sequence_of_statements fi

IF Statements IF-THEN-ELSE The sequence of statements in the ELSE clause is executed only if the condition is false or null. Thus, the ELSE clause ensures that a sequence of statements is executed. In the following example, the first UPDATE statement is executed when the condition is true, but the second UPDATE statement is executed when the condition is false or null: if [ condition ] then sequence_of_statements1 else sequence_of_statements2 fi

IF Statements IF-THEN-ELSIF If the first condition is false or null, the ELSIF clause tests another condition. An IF statement can have any number of ELSIF clauses; the final ELSE clause is optional. Conditions are evaluated one by one from top to bottom. If any condition is true, its associated sequence of statements is executed and control passes to the next statement. If all conditions are false or null, the sequence in the ELSE clause is executed. Consider the following example: if [ condition1] then sequence_of_statements1 elif [ condition2 ] then sequence_of_statements2 else sequence_of_statements3 fi

CASE Statement CASE A special version of the if-then-else where you test specific values. Each value precedes a right parenthese ) and ends with double semi colon. * is the default case : case <variable> in A) sequence_of_statements1 ;; B) sequence_of_statements2 ;; *) sequence_of_statements3 ;; esac

LOOP Statements WHILE-LOOP Before each iteration of the loop, the condition is evaluated. If the condition is true, the sequence of statements is executed, then control resumes at the top of the loop. If the condition is false or null, the loop is bypassed and control passes to the next statement. An example follows: while [ condition ] do sequence_of_statements done

LOOP Statements UNTIL-LOOP Before each iteration of the loop, the condition is evaluated. If the condition is false or null, the sequence of statements is executed, then control resumes at the top of the loop. If the condition is true, the loop is bypassed and control passes to the next statement. An example follows: until [ condition ] do sequence_of_statements done

LOOP Statements FOR-LOOP Whereas the number of iterations through a WHILE or UNTIL loop is unknown until the loop completes, the number of iterations through a FOR loop is known before the loop is entered. FOR loops iterate over a specified range of values. The syntax follows: for <variable> in list do sequence_of_statements done