Title:[ Variables Comparison Operators If Else Statements ]

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

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

CS Unix Tools & Scripting

bash Execution Control COMP2101 Winter 2019

Shell script/program. Basic shell scripting. Script execution. Resources. Simple example script. Quoting

Bash scripting basics

Shell Start-up and Configuration Files

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Conditional Control Structures. Dr.T.Logeswari

Shell programming. Introduction to Operating Systems

Lab 4: Shell scripting

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

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

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

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

Computer Systems and Architecture

A shell can be used in one of two ways:

Bourne Shell Reference

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

COMP 4/6262: Programming UNIX

1. Hello World Bash Shell Script. Last Updated on Wednesday, 13 April :03

Control Structures. CIS 118 Intro to LINUX

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

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

Useful Unix Commands Cheat Sheet

What is Bash Shell Scripting?

Computer Systems and Architecture

Bashed One Too Many Times. Features of the Bash Shell St. Louis Unix Users Group Jeff Muse, Jan 14, 2009

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

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

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

Shell scripting and system variables. HORT Lecture 5 Instructor: Kranthi Varala

Linux shell programming for Raspberry Pi Users - 2

Essentials for Scientific Computing: Bash Shell Scripting Day 3

2. λ is a regular expression and denotes the set {λ} 4. If r and s are regular expressions denoting the languages R and S, respectively

Linux 系统介绍 (III) 袁华

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo

Shell Programming (bash)

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

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

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

CS Unix Tools & Scripting

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

UNIX shell scripting

Vi & Shell Scripting

Linux Bash Shell Scripting

Basic Linux (Bash) Commands

Perl. Interview Questions and Answers

LING 408/508: Computational Techniques for Linguists. Lecture 5

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

Language Reference Manual

9.2 Linux Essentials Exam Objectives

More Scripting and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Shells & Shell Programming (Part B)

Welcome to the Bash Workshop!

Shell Programming (Part 2)

Typescript on LLVM Language Reference Manual

EECS2301. Example. Testing 3/22/2017. Linux/Unix Part 3. for SCRIPT in /path/to/scripts/dir/* do if [ -f $SCRIPT -a -x $SCRIPT ] then $SCRIPT fi done

12.1 UNDERSTANDING UNIX SHELL PROGRAMMING LANGUAGE: AN INTRODUCTION Writing a Simple Script Executing a Script

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

Practice 5 Batch & Shell Programming

Practical 04: UNIX / LINUX Shell Programming 1

Shell scripting Scripting and Computer Environment - Lecture 5

BASH Programming Introduction

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

Bash Reference Manual Reference Documentation for Bash Edition 2.5b, for Bash Version 2.05b. July 2002

Last Time. on the website

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

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

Lecture 5. Essential skills for bioinformatics: Unix/Linux

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

Basic Shell Scripting

bash Tests and Looping Administrative Shell Scripting COMP2101 Fall 2017

Bash Programming. Student Workbook

bash Args, Signals, Functions Administrative Shell Scripting COMP2101 Fall 2017

Processes and Shells

CS 25200: Systems Programming. Lecture 10: Shell Scripting in Bash

Common File System Commands

Scripting versus Programming

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

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

CSC 2500: Unix Lab Fall 2016

Introduction to Bash Programming. Dr. Xiaolan Zhang Spring 2013 Dept. of Computer & Information Sciences Fordham University

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

Bourne Shell (ch 8) Overview. Bourne Shell. Bourne Shell. Bourne Shell. Bourne Shell. Redirect standard error. Redirect standard error

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

Lexical Considerations

Output with printf Input. from a file from a command arguments from the command read

Review. Preview. Functions. Functions. Functions with Local Variables. Functions with Local Variables 9/11/2017

More Scripting Todd Kelley CST8207 Todd Kelley 1

Shells and Shell Programming

INTRODUCTION TO SHELL SCRIPTING Dr. Jeffrey Frey University of Delaware, IT

Shells and Shell Programming

Geophysics 501. Computa3onal Methods for the Geosciences. Flow Control and Lists. Zach Zens

Essential Skills for Bioinformatics: Unix/Linux

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

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Shell Scripting. Winter 2019

Chapter 4. Unix Tutorial. Unix Shell

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

Transcription:

[Color Codes] Environmental Variables: PATH What is path? PATH=$PATH:/MyFolder/YourStuff?Scripts ENV HOME PWD SHELL PS1 EDITOR Showing default text editor

#!/bin/bash a=375 hello=$a #No space permitted on either side of = sign when initializing variables. # VARIABLE =value Script tries to run VARIABLE command with one argument, =value. # VARIABLE = value #Script tries to run value command with the environmental variable VARIABLE set to. echo hello #hello echo $hello #375 echo ${hello} #375

Quoting Variable Enclosing a referenced value in double quotes (... ) does not interfere with variable substitution. This is called partial quoting. ( ) causes the variable name to be used literally. echo $hello #375 echo ${hello} #375 hello= AB C D echo $hello #ABCD echo $hello #AB C D #Quoting a variable preserves whitespace echo $hello #$hello # Setting multiple variables on the same line var=21 var2=22 var3=$v3 hello = #setting it into a null value echo \$hello (null value) = $hello #$hello (null value) = #Note that setting a variable to a null value is not the same as unsetting it, although the end result is the same numbers= one two three other_numbers= 1 2 3 If there is a white space embedded with a variable, then quotes are necessary. other_numbers=1 2 3 # Gives an error message echo numbers=$numbers #number=one two three echo uninitialized_variable = $uninitialized_variable

# Uninitialized variable has null value (no value) uninitialized_variable= # Declaring, but not initializing it, same as setting it to a null value, as above. echo uninitialized_variable = $uninitialized_variable #It still has a null value uninitialized_variable=23 #set it. unset uninitialized_variable #Unset it. echo uninitialized_variable = $uninitialized_variable # uninitialized_variable = it still has a null value echo $uninitialized #(blank line) let uninitialized = $uninitialized +5 [next two bullets] pg 8 The Bash escape sequences: Escaping is a method of quoting single characters. The escape (\) preceding a character tell the shell to interpret that character literally \n means newline \r means return \t means tab \v means vertical tab \b means backspace \a means alert (beep or flash) \0xx translates to the octal ASCll = of Onn, where nn is a string of digits

Bash Shell Operators Comparison Operators Bash Tests Arithmetic Operators Assignment Operators Logical and Bitwise Operators eq is equal to if[ $a eq $b ] ne is not equal to if[ $a ne $b ] gt is greater than if[ $a gt $b ] ge is greater than or equal to if[ $a ge $b ] lt is less than if[ $a lt $b ] le is less than or equal to if[ $a le $b ] Double Parenthesis

< is less than (( $a < $b )) <= is less than or equal to (( $a <= $b )) > is greater than (( $a > $b )) >= is greater than or equal to (( $a >= $b )) = is equal to if[ $a = $b ] == is equal to if[ $a == $b ]!= is not equal to if[ $a!= $b ] This operator uses pattern matching within a [[ ]] construct. ASCll alphabetical < is less than if[ $a \< $b ] if[[ $a < $b ]] Bash Test Bash has the test command: if [ condition true] if [ condition1 ] then then command2 command2 else fi command2 elif [ condition2 ] then command2 else fi

#!/bin/bash if [ foo = foo ]; then echo expression evaluated as true fi #!/bin/bash T1= foo T2= bar if [ $T1 = $T2 ]; then echo expression evaluated as true else echo expression evaluated as false fi