Linux shell & shell scripting - II

Similar documents
Introduction: What is Unix?


Introduction of Linux. Huang Cheng-Chao Dept. of Comput. Sci. & Tech. East China Normal University


Vi & Shell Scripting

Basic Linux (Bash) Commands

Bash scripting basics

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

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

Essential Skills for Bioinformatics: Unix/Linux

Useful Unix Commands Cheat Sheet

Practical 02. Bash & shell scripting

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.

UNIX II:grep, awk, sed. October 30, 2017

Part 1: Basic Commands/U3li3es

Shell Programming (bash)

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Linux Shell Script. J. K. Mandal

SHELL SCRIPT BASIC. UNIX Programming 2014 Fall by Euiseong Seo

Introduction to the shell Part II

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

Practical Linux examples: Exercises

5/20/2007. Touring Essential Programs

DAVE LIDDAMENT INTRODUCTION TO BASH

SHELL SCRIPT BASIC. UNIX Programming 2015 Fall by Euiseong Seo


Grep and Shell Programming

9.2 Linux Essentials Exam Objectives

Lecture #13 AWK Part I (Chapter 6)

Lecture 5. Essential skills for bioinformatics: Unix/Linux

Essentials for Scientific Computing: Bash Shell Scripting Day 3

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction to Linux. Roman Cheplyaka

COMP 4/6262: Programming UNIX

UNIX shell scripting

Chapter 9. Shell and Kernel

CENG 334 Computer Networks. Laboratory I Linux Tutorial

When talking about how to launch commands and other things that is to be typed into the terminal, the following syntax is used:

Shells & Shell Programming (Part B)

Unix as a Platform Exercises + Solutions. Course Code: OS 01 UNXPLAT

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

Introduction To. Barry Grant

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

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

Mills HPC Tutorial Series. Linux Basics I

CS Unix Tools & Scripting

sottotitolo A.A. 2016/17 Federico Reghenzani, Alessandro Barenghi


Answers to AWK problems. Shell-Programming. Future: Using loops to automate tasks. Download and Install: Python (Windows only.) R

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

A shell can be used in one of two ways:

Programming introduction part I:

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

The Unix Shell & Shell Scripts

Working With Unix. Scott A. Handley* September 15, *Adapted from UNIX introduction material created by Dr. Julian Catchen

Advanced Linux Commands & Shell Scripting

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

INTRODUCTION TO BIOINFORMATICS

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Lec 1 add-on: Linux Intro

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

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

/smlcodes /smlcodes /smlcodes. Shell Scripting TUTORIAL. Small Codes. Programming Simplified. A SmlCodes.Com Small presentation

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

CS CS Tutorial 2 2 Winter 2018

Open up a terminal, make sure you are in your home directory, and run the command.

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

Lecture 2. Regular Expression Parsing Awk

Lab 5a Shell Script Lab 4 Using Arithmetic Operators in shell script

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Short Read Sequencing Analysis Workshop

Shells and Shell Programming

Unix Introduction to UNIX

Unix basics exercise MBV-INFX410

Basic Shell Scripting

Practice 5 Batch & Shell Programming

Assignment 3, Due October 4

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

Shells and Shell Programming

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

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

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

Introduction to the Linux Command Line

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

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

Bourne Shell Reference

Linux Bash Shell Scripting

Title:[ Variables Comparison Operators If Else Statements ]

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Files

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CISC 220 fall 2011, set 1: Linux basics

Practical Session 0 Introduction to Linux

Using echo command in shell script

Recap From Last Time: Setup Checklist BGGN 213. Todays Menu. Introduction to UNIX.

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Lab 3a Using the vi editor

Introduction to UNIX command-line II

Part I. UNIX Workshop Series: Quick-Start

Transcription:

IBS 574 - Computational Biology & Bioinformatics Spring 2018, Tuesday (02/01), 2:00-4:00PM Linux shell & shell scripting - II Ashok R. Dinasarapu Ph.D Scientist, Bioinformatics Dept. of Human Genetics, Emory University, Atlanta 1

What is Shell scripting? A script is a collection of commands stored in a file. Shell is a command-line interpreter. To execute a shell script, ex. hello.sh./hello.sh../hello.sh /home/user_name/script/hello.sh bash hello.sh (or sh hello.sh) 2

Easiest way to do this is Start typing! 3

Connecting Server via SSH SSH allows you to connect to your server securely and perform Linux command-line operations. ssh user_name@blnx1.emory.edu Alternatively, https://blnx1.emory.edu:22443/ user_name@blnx1:~$ ~ means your home directory (/home/user_name) Windows: download PuTTY https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html 1/30/2018, 2-4PM 4

mkdir & directory structure Create directories from your home directory (i.e /home/user_name) Usage: mkdir -p project/{data,script,out,log} project/data project/script project/out project/log Usage: cd project/script 5

HowTo: Create/Edit text files Choose a text editor: emacs, Vim INSERT mode: Usage: vi hello.sh press keys like i OR a & start typing. "i" will let you insert text just before the cursor. "I" inserts text at the beginning of the current line. "a" will let you insert text just after the cursor, and "A" will let you type at the end of the current line. 6

HowTo: Create/Edit text files Type the following text: #!/bin/sh # My first script echo "Hello World!" #!/bin/sh a special clue given to the shell indicating what program is used to interpret the script. 7

HowTo: Create/Edit text files Type the following text: #!/bin/sh # My first script #!/bin/bash #!/usr/bin/perl #!/usr/bin/rscript #!/usr/bin/env python echo "Hello World!" View symbolic link using ls la /bin/sh #!/bin/sh a special clue given to the shell indicating what program is used to interpret the script. 8

HowTo: Save file in Vi Text Editor SAVE mode: press esc key AND :q! for not to save OR :x to save all typed content. Alternatively, use :wq for write and quit (save and exit) 9

chmod Change the permissions of files Read (r), write (w), and execute (x) 3 types of users (user, group & other) Usage: ls -l 10

make file executable To make it executable Usage: chmod +rwxr-xr-x hello.sh Usage: chmod +x hello.sh Usage:./hello.sh To make it un-executable Usage: chmod -x hello.sh 11

make file executable To make it executable +755 Usage: chmod +rwxr-xr-x hello.sh Usage: chmod +x hello.sh Usage:./hello.sh To make it un-executable Usage: chmod -x hello.sh 12

Variables in Linux/Shell Usage: vi hello.sh #!/bin/bash # My first script i=22 echo Hello, I am $i # echo Hello, I am $i Usage:./hello.sh 13

Variables in Linux/Shell Usage: vi hello.sh #!/bin/bash # My first script i=22 j="hello, I am echo $j $i Usage:./hello.sh 14

Variable expansion in Linux/Shell Usage: vi hello.sh #!/bin/bash # My first script i=22 j=${i}0 K=${i}1 echo $i $j $k the {} in ${} are useful if you want to expand the variable Usage:./hello.sh 15

Conditions in Linux/Shell #!/bin/bash # My first script PASS= test1234 Usage: vi hello.sh if [ $PASS== test1234 ]; then echo Correct pass word!! fi Usage:./hello.sh Remember that the spacing is very important in the if statement. 16

Conditions in Linux/Shell #!/bin/bash # My first script PASS= test123 Usage: vi hello.sh if [ $PASS== test1234 ]; then echo Correct pass word!! else echo enter correct pass word!! fi Usage:./hello.sh 17

for loop in Linux/Shell Usage: vi hello.sh #!/bin/bash # My first script for i in {1..10}; do echo $i # echo ${i}a done Usage:./hello.sh 18

for loop in Linux/Shell Usage: vi hello.sh #!/bin/bash # My first script for i in {1..10}; do echo $i # echo ${i}a done Alternatively, $(seq 0 1 10) $(seq 0 2 10) 1 2 3 4 5 6 7 8 9 10 Usage:./hello.sh 19

Array in Linux/Shell Usage: vi hello.sh #!/bin/bash arr=( A B C D E ) for i in {0..4}; do echo $i echo ${arr[$i]} done Usage:./hello.sh 20

for loop in Linux/Shell Usage: vi hello.sh #!/bin/sh # My first script for i in 1 2 3 x y z do echo $i done loop indices doesn't have to be just numbers!!! {1..3} x y z bash supports Usage:./hello.sh 21

while loop in Linux/Shell #!/bin/bash # My first script Usage: vi hello.sh i=0 while [ $i -le 5 ]; do # echo before $i i=$(( $i+1 )) echo after $i done Usage:./hello.sh 22

Functions in Linux/Shell Usage: vi hello.sh #!/bin/bash # function definition add_user() { USER=$1 PASS=$2 echo Passwd $PASS created for $USER on $(date) } # function call echo $(add_user bob letmein) Usage:./hello.sh 23

Functions in Linux/Shell Usage: vi hello.sh #!/bin/bash # function definition add_user() { # USER=$1 # PASS=$2 echo Passwd $1 created for $2 on $3 } # function call echo $(add_user bob letmein $(date) ) Usage:./hello.sh 24

download a fastq file Usage: cd project/data wget https://github.com/cgatoxford/umi-tools/ releases/download/v0.2.3/example.fastq.gz View Usage: zcat example.fastq.gz head Check file size Usage: ls -lh example.fastq.gz Count number of sequences in a fastq file Usage: grep -c "^@" example.fastq.gz 25

A FASTQ file normally uses four lines per sequence zcat example.fastq.gz head Sequence ID @SRR2057595.7 CAGGTTCAATCTCGGTGGGACCTC Sequence +SRR2057595.7 1=DFFFFHHHHHJJJFGIJIJJIJ @SRR2057595.9 TTGGTTCAATCTGATGCCCTCTTCTGGTGCATCTGAAGACAGCTACAGTGTACTTAGATATAATAAATAAATCTT +SRR2057595.9 4=DFDBDHHFHHIGGEHJGGIHGHGGCAFCHGIGEHIJJJJIJJJIHIIIIIIJIIIIIGHIIGGIJGIIJIIJ@ @SRR2057595.14 TGGGTTAATGCGGCCCCGGGTTCCTCCCGGGGCTACGCCTGTCTGAGCGTCGCT 26

Calculate the length of reads Create the following executable file at project/script Usage: vi fastq.sh #!/bin/bash # cd project/log (to run this script from log directory) zcat../data/example.fastq.gz \ awk {if(nr%4==2) print length($1)} >../out/length.txt Usage:../script/fastq.sh 27

Usage: vi hist.r Plot - Histogram Create the following executable file at project/script #!/usr/bin/rscript # cd project/log (to run this script from log dir) t.dat <- read.table(../out/length.txt ) jpeg(../out/rplot.jpg ) hist(t.dat[,1]) dev.off() Usage:../script/hist.R 28

Calculate the length of reads Create the following executable file at project/script #!/bin/bash # cd project/log (to run this script from log directory) zcat../data/example.fastq.gz \ awk {if(nr%4==2) print length($1)} >../out/length.txt # include R script and run../script/hist.r Usage: vi fastq.sh Usage:../script/fastq.sh 29

Calculate the length of reads Create the following executable file at project/script Usage: vi fastq.sh #!/bin/bash # cd project/log (to run this script from log directory) zcat../data/example.fastq.gz \ awk {if(nr%4==2) print length($1)} >../out/length.txt # include R script and run../script/hist.r Usage:../script/fastq.sh 2>error.log Redirect error output to a file 30

Open/View Image Login as interactive mode Usage: ssh -Y user_name@blnx1.emory.edu Usage: xdg-open rplot.jpg -X Enables X11 forwarding -Y Enables trusted X11 forwarding X11 is the X Window System To download from server: rsync -av adinasarapu@blnx1.emory.edu:~/project/out/rplot.jpg /Users/adinasarapu/ 31

AWK AWK is an interpreted programming language & designed for text processing. The word "AWK" is derived from the initials of the language's three developers: A. Aho, B. W. Kernighan and P. Weinberger. Following are the variants of AWK AWK - the (very old) original from AT&T NAWK - A newer, improved version from AT&T GAWK It is GNU AWK. The Free Software foundation's version 32

Basic Structure of AWK pattern { action } The pattern specifies when the action is performed. By default, AWK execute commands on every line. AWK reads a line from the input stream (file, pipe, or STDIN) This process repeats until the file reaches its end. 33

Basic Structure of AWK pattern { action } Two other important patterns are specified by the keywords "BEGIN" and "END BEGIN { print "START" } pattern { print } END { print "STOP" } BEGIN block executes only once. This is good place to initialize variables. The body block applies AWK commands on every input line. The END block executes at the end of the program. 34

File processing/printing records Choose a text editor: emacs, Vim Usage: vi marks.txt 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89 awk '{print}' < marks.txt awk 'BEGIN{printf "SNo\tName\tSub\tMarks\n"}{print}' < marks.txt 35

Printing Fields (Columns) Choose a text editor: emacs, Vim Usage: vi marks.txt 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89 awk '{print}' < marks.txt awk '{print $0}' < marks.txt awk '{print $1,$2,$3,$4}' < marks.txt (space) awk '{print $1"\t"$2"\t"$3"\t"$4}' < marks.txt (tab) 36

Printing Columns by Pattern Choose a text editor: emacs, Vim Usage: vi marks.txt 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89 awk /E/ {print}' < marks.txt awk /E/' < marks.txt awk '/A/ {print $2"\t"$4}' < marks.txt (tab) 37

Count by Pattern match Choose a text editor: emacs, Vim Usage: vi marks.txt awk 'BEGIN{i=0} /A/ {i+=1} END{print i} ' < marks.txt 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89 awk 'BEGIN{i=0} /A/ {i+=1} END{print i}' < marks.txt 38

Count by Pattern match Choose a text editor: emacs, Vim Usage: vi marks.txt awk \ 'BEGIN{i=0} \ /A/ {i+=1} \ END{print i} \ ' < marks.txt 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89 awk is one-liner awk 'BEGIN{i=0} /A/ {i+=1} END{print i}' < marks.txt 39

Count by Pattern match Choose a text editor: emacs, Vim Usage: vi marks.txt #!/bin/bash awk 'BEGIN{i=0} /A/ {i+=1} END{print i} ' < marks.txt 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89./marks.sh 40

Count by Pattern match Choose a text editor: emacs, Vim Usage: vi marks.txt #!/usr/bin/awk f BEGIN{i=0} /A/ {i+=1} END{print i} 1 Amit Physics 88 2 Ralf Maths 90 3 Shyam Biology 87 4 Kedar English 85 5 Ashok History 89 awk -f marks.awk < marks.txt 41

Standard AWK variables env XDG_SESSION_ID=38 TERM=xterm-256color SHELL=/bin/bash SSH_CLIENT=10.110.52.30 28952 22 SSH_TTY=/dev/pts/8 USER=adinasarapu awk 'BEGIN {print ENVIRON["USER"]} ' awk 'BEGIN {print ENVIRON["SHELL"]} ' awk 'BEGIN {print ENVIRON["HOSTNAME"]} awk 'END { print FILENAME }' marks.txt (Please note that FILENAME is undefined in the BEGIN block) 42

Standard AWK variables FS, OFS, RS, ORS, NR and NF FS: Input Field Separator (default is space) OFS: Output Field Separator (default is space) env awk 'BEGIN{FS="=";}{print $1} env awk 'BEGIN{FS="="; OFS=":"}{print $1,$2}' 43

Standard AWK variables FS, OFS, RS, ORS, NR and NF FS: Input Field Separator (default is space) OFS: Output Field Separator (default is space) awk '{print $1,$2,$3,$4}' < marks.txt (space) awk '{print $1"\t"$2"\t"$3"\t"$4}' < marks.txt (tab) awk 'BEGIN{FS="\t"; OFS="\t"}{print $1,$2,$3,$4}' < marks.txt 44

Standard AWK variables FS, OFS, RS, ORS, NR and NF FS: Input Field Separator (default is space) OFS: Output Field Separator (default is space) awk '{print $1,$2,$3,$4}' < marks.txt (space) awk '{print $1"\t"$2"\t"$3"\t"$4}' < marks.txt (tab) awk 'BEGIN{FS="\t"; OFS="\t"}{print $1,$2,$3,$4}' < marks.txt awk -F'\t' 'BEGIN{OFS="\t"}{print $1,$2,$3,$4}' < marks.txt 45

Standard AWK variables FS, OFS, RS, ORS, NR and NF RS: Input Record Separator (default is Newline) ORS: Output Record Separator (default is Newline) awk '{print $1,$2,$3,$4}' < marks.txt (space) awk '{print $1"\t"$2"\t"$3"\t"$4}' < marks.txt (tab) awk 'BEGIN{FS="\t"; OFS="\t"}{print $2,$4}' < marks.txt awk 'BEGIN{OFS=":"; ORS=";"}{print $2,$4} END{print "\n"}' < marks.txt 46

Standard AWK variables NR: Record number NF: Number of Fields in a Record cat marks.txt awk '{print NR,"->",NF} ' cat marks.txt awk 'NR<4' FS, OFS, RS, ORS, NR and NF cat marks.txt wc l (Number of lines/rows) cat marks.txt wc w (Number of words) (get first 3 records) cat marks.txt awk '{print NR}' tail -1 (number of records) cat marks.txt awk '{ total = total + NF } END { print total }' 47

if or if else AWK - Control Flow AWK provides conditional statements to control the flow of a program #!/bin/bash awk 'BEGIN { num =10; if (num % 2 == 0) printf "%d is even number.\n", num; else printf "%d is odd number.\n", num }' ' 48

for loop AWK - Control Flow AWK provides conditional statements to control the flow of a program in is used while accessing array elements #!/bin/bash awk 'BEGIN { arr[0] = 11; arr[1] = 22; arr[2] = 33; for(i in arr) printf "%d is a number.\n", arr[i] }' ' awk 'BEGIN { arr[0]=11; arr[1]=22; for(i in arr) printf "%d is a number.\n", arr[i] }' 49

zcat example.fastq.gz head AWK - Control Flow A FASTQ file normally uses four lines per sequence Sequence ID @SRR2057595.7 CAGGTTCAATCTCGGTGGGACCTC Sequence +SRR2057595.7 1=DFFFFHHHHHJJJFGIJIJJIJ @SRR2057595.9 TTGGTTCAATCTGATGCCCTCTTCTGGTGCATCTGAAGACAGCTACAGTGTACTTAGATATAATAAATAAATCTT +SRR2057595.9 4=DFDBDHHFHHIGGEHJGGIHGHGGCAFCHGIGEHIJJJJIJJJIHIIIIIIJIIIIIGHIIGGIJGIIJIIJ@ @SRR2057595.14 TGGGTTAATGCGGCCCCGGGTTCCTCCCGGGGCTACGCCTGTCTGAGCGTCGCT Line 1 begins with a '@' character and is followed by a sequence identifier Line 2 is the raw sequence letters Line 3 begins with a '+' character and is optionally followed by the same sequence identifier Line 4 encodes the quality values for the sequence in Line 2 50

zcat example.fastq.gz head AWK - Control Flow A FASTQ file normally uses four lines per sequence Sequence ID @SRR2057595.7 CAGGTTCAATCTCGGTGGGACCTC Sequence +SRR2057595.7 1=DFFFFHHHHHJJJFGIJIJJIJ @SRR2057595.9 TTGGTTCAATCTGATGCCCTCTTCTGGTGCATCTGAAGACAGCTACAGTGTACTTAGATATAATAAATAAATCTT +SRR2057595.9 4=DFDBDHHFHHIGGEHJGGIHGHGGCAFCHGIGEHIJJJJIJJJIHIIIIIIJIIIIIGHIIGGIJGIIJIIJ@ @SRR2057595.14 TGGGTTAATGCGGCCCCGGGTTCCTCCCGGGGCTACGCCTGTCTGAGCGTCGCT zcat example.fastq.gz awk '{if(nr%4==2) print}' head -20 zcat example.fastq.gz awk '{if(nr%4==2) print $1}' head -20 zcat example.fastq.gz awk '{if(nr%4==2) {print substr($0,1,10)}}' head -20 zcat example.fastq.gz awk 'END{print NR/4} 51

AWK - Control Flow # Separate (filter) FASTQ reads based on their length #!/bin/bash zcat example.fastq.gz \ awk 'NR%4 == 1 {ID=$0} NR%4==2 {SEQ=$0} NR%4==3 {PLUS=$0} NR%4==0 {QUAL=$0} { seqlen=length(seq) qualen=length(qual) if(seqlen==qualen&&seqlen>=75) print ID"\n"SEQ"\n"PLUS"\n"QUAL \ "gzip > filtered.fastq.gz" } ' 52

AWK - Control Flow # Separate (filter) FASTQ reads based on their length #!/bin/bash zcat example.fastq.gz \ awk 'NR%4 == 1 {ID=$0} NR%4==2 {SEQ=$0} NR%4==3 {PLUS=$0} NR%4==0 {QUAL=$0} { seqlen=length(seq) qualen=length(qual) if(seqlen==qualen&&seqlen>=75) print ID"\n"SEQ"\n"PLUS"\n"QUAL \ "gzip > filtered.fastq.gz" } ' echo $((1%4)) 1 echo $((2%4)) 2 echo $((3%4)) 3 echo $((4%4)) 0 echo $((5%4)) 1 echo $((6%4)) 2 echo $((7%4)) 3 echo $((8%4)) 0 53

Practice Makes Perfect Thank you 54

String Comparison Operators Operator Description Example = or == Is Equal To if [ "$1" == "$2" ]!= Is Not Equal To if [ "$1"!= "$2" ] > Is Greater Than (ASCII comparison) if [ "$1" > "$2" ] >= Is Greater Than Or Equal To if [ "$1" >= "$2" ] < Is Less Than if [ "$1" < "$2" ] <= Is Less Than Or Equal To if [ "$1" <= "$2" ] -n Is Not Null if [ -n "$1" ] -z Is Null (Zero Length String) if [ -z "$1"] 55

Integer Comparison Operators Operator Description Example -eq Is Equal To if [ $1 -eq 200 ] -ne Is Not Equal To if [ $1 -ne 1 ] -gt Is Greater Than if [ $1 -gt 15 ] -ge Is Greater Than Or Equal To if [ $1 -ge 10 ] -lt Is Less Than if [ $1 -lt 5 ] -le Is Less Than Or Equal To if [ $1 -le 0 ] == Is Equal To if (( $1 == $2 ))!= Is Not Equal To if (( $1!= $2 )) < Is Less Than if (( $1 < $2 )) <= Is Less Than Or Equal To if (( $1 <= $2 )) > Is Greater Than if (( $1 > $2 )) >= Is Greater Than Or Equal To if (( $1 >= $2 )) 56