Bash Script. CIRC Summer School 2015 Baowei Liu

Similar documents
Part III. Shell Config. Tobias Neckel: Scripting with Bash and Python Compact Max-Planck, February 16-26,

Review of Fundamentals

BASH SHELL SCRIPT 1- Introduction to Shell

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

IB047. Unix Text Tools. Pavel Rychlý Mar 3.

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

Basic Linux (Bash) Commands

Week Overview. Simple filter commands: head, tail, cut, sort, tr, wc grep utility stdin, stdout, stderr Redirection and piping /dev/null file

ITST Searching, Extracting & Archiving Data

Useful Unix Commands Cheat Sheet

Advanced training. Linux components Command shell. LiLux a.s.b.l.

CST Algonquin College 2

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

Advanced Linux Commands & Shell Scripting

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

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

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

Essentials for Scientific Computing: Stream editing with sed and awk

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

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Linux shell programming for Raspberry Pi Users - 2

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

The Unix Shell. Pipes and Filters

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

INTRODUCTION TO SHELL SCRIPTING ITPART 2

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St.

UNIX Shell Programming

CSE 15L Winter Midterm :) Review

Module 8 Pipes, Redirection and REGEX

Introduction To. Barry Grant

Lecture 3 Tonight we dine in shell. Hands-On Unix System Administration DeCal

5/8/2012. Exploring Utilities Chapter 5

Automating Tasks Using bash

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

Systems Programming/ C and UNIX

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

Getting to grips with Unix and the Linux family

Basics. I think that the later is better.

CSC209 Review. Yeah! We made it!

5/20/2007. Touring Essential Programs

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

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

CS214-AdvancedUNIX. Lecture 2 Basic commands and regular expressions. Ymir Vigfusson. CS214 p.1

Common File System Commands

Bash print to stderr

Regex, Sed, Awk. Arindam Fadikar. December 12, 2017

Shells and Shell Programming

Topic 4: Grep, Find & Sed

My Favorite bash Tips and Tricks

CSE 490c Autumn 2004 Midterm 1

Shells & Shell Programming (Part B)

Computer Systems and Architecture

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

CS395T: Introduction to Scientific and Technical Computing

Linux II and III. Douglas Scofield. Crea-ng directories and files 15/08/16. Evolu6onary Biology Centre, Uppsala University

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Chapter 1 - Introduction. September 8, 2016

Processes and Shells

Prerequisites: Students should be comfortable with computers. No familiarity with Linux or other Unix operating systems is required.

Introduction to the shell Part II

Computer Systems and Architecture

ERIE COMMUNITY COLLEGE COURSE OUTLINE. DA155 Operating Systems and Shell Scripting

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

Linux Fundamentals (L-120)

Practical Linux Examples

STATS Data Analysis using Python. Lecture 15: Advanced Command Line

EECS2301. Lab 1 Winter 2016

Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

Regular Expressions 1

Lecture 18 Regular Expressions

Understanding bash. Prof. Chris GauthierDickey COMP 2400, Fall 2008

LINUX FUNDAMENTALS. Supported Distributions: Red Hat Enterprise Linux 6 SUSE Linux Enterprise 11 Ubuntu LTS. Recommended Class Length: 5 days

Shell Programming Overview

ECE 364 Software Engineering Tools Lab. Lecture 2 Bash II

5/8/2012. Specifying Instructions to the Shell Chapter 8

Language Reference Manual

Introduction: What is Unix?

BASH and command line utilities Variables Conditional Commands Loop Commands BASH scripts

Shells and Shell Programming

Practical Linux examples: Exercises

Introduction to UNIX Part II

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

We d like to hear your suggestions for improving our indexes. Send to

Week 5 Lesson 5 02/28/18

Introduction to Unix/Linux INX_S17, Day 8,

CSC UNIX System, Spring 2015

Bourne Shell Reference

Do Not Fear the Command Line

Recap From Last Time:

BGGN 213 Working with UNIX Barry Grant

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

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming


Manual Shell Script Linux If Not Equal String Comparison

85321, Systems Administration Chapter 6: The shell

CSC Web Programming. Introduction to JavaScript

Part 1: Basic Commands/U3li3es

LINUX FUNDAMENTALS (5 Day)

Shell Programming Systems Skills in C and Unix

Transcription:

Bash Script CIRC Summer School 2015 Baowei Liu

Filename Expansion / Globbing Expanding filenames containing special characters Wild cards *?, not include... Square brackets [set]: - Special characters:! (other than) Quote special pattern character if they are to be matched literally Escaping backslash: protect a subsequent special character

File Manipulation Examine the status of a file -a file: True if file exists -s file: True if file exists and has a size greater than zero -f file: True if file exists and is a regular file Compare files file1 nt file2: newer than file1 ot file2: older than

Merge files join: merge files by a common column cat: merge files by rows

Arrays Array is a numbered list One-dimensional only Create an array with = and (), or declare a Array element: ArrayName[index] Access elements: ${ArrayName[n]} @, * Array size:${#arrayname([@])},${#arrayname([*])} Initialize an array with brace expansion Delete array or element: unset ArrayName[n] Add element without key: ArrayName+=(...)

Strings and Manipulation Create a string Display a string Length of a string Substring: a Bash string just holds one element Compare strings: Concatenate of string Substring extraction: position starting with 0 Substring replacement

Compare Strings =: [[ $a = $b ]], white space are important!!!= -z True if the string is null /zero-length -n True if the string is Not null

Substring Extraction ${string:position:length} ${string:position}

Substring Removal ${string#substring} ${string##substring} ${string%substring} ${string%%substring}

Substring Replacement ${string/substring/replacement} ${string//substring/replacement} ${string/#substring/replacement} ${string/%substring/replacement}

grep and Regular Expression grep: search for matches to a pattern in a file and print the matched line to stdout grep PATTERN file Regular Expression: a sequence of characters that define a search pattern, mainly for string match -- globbing pattern used for text

Regular Expression. : Equivalent to? in filename expansion.*: any string. Equivalent to * in filename expansion * : zero or more times, a* will match a,aa, but not ab ^: starting with, ^ab $: ending with, ab$

Regular Expression []: [-] [^ ] \< >\ exact word

sed and Regular Expressions sed s/abc/xyz File: All occurrences sed 5,10s/abc/xyz File: specified lines sed 0~2 s/abc/xyz/ File: only in the even lines More complicated examples

sed and Regular Expressions Word Characters: Alphanumeric characters plus _ [A-Za-z0-9_] Replace all occurrences in a line

awk A text-processing programming language in Linux awk {print $1} Floating number calculations

head and tail n c -f

wc wc: print the number of bytes, words and lines in a file. -c -l -w

Some Examples

Scenarios & Examples Using Bash Script Multiple command lines / complicated command lines: convert movie System monitoring tasks: back fill Run jobs periodically: revision monitor Wrappers

Slurm Job Scheduler Slurm 1. Free and open-source job scheduler 2. Arbitrate resources by managing a queue of pending jobs 3. Examples for submitting jobs to our local systems can be found on info.circ.rochester.edu http://en.wikipedia.org/wiki/slurm_workload_manager

Job Scheduler Cron Time-based job scheduler Schedule the command to run with crontab e Each line of a crontab file represents a job

Cron and Crontab Specify the time: * * * * * script/command min hr dom m dow(0-6) Specify every five hour * */5 * * * script/command 0 0 1 1,6 * script/command Non standard macros @yearly @reboot

Stdin, stdout and stderr Stdin: standard in, data stream that is going into a process Stdout: data stream coming from a running process Stderr: data stream of error messages being generated by a process

Redirect and Pipes Redirect between files including the three file descriptors, stdin, stdout and stder: > >> Pipes takes the output of one command as the input of another command