Copyright 2009 der.hans intro over a decade as sysadmin, programmer, analyst, data janitor currently director of engineering for a startup adjunct instructor.

Slides:



Advertisements
Similar presentations
7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
Advertisements

CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Linux+ Guide to Linux Certification, Second Edition
The UNIX Shells 1. What is a Unix shell? 2. A few common shells in the Unix & Linux. A. Bourne shell B. Korn shell C. C shell D. Bash-the default shell.
Scripting Languages CS351 – Programming Paradigms.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Shell Script Examples.
Regular Expressions A regular expression defines a pattern of characters to be found in a string Regular expressions are made up of – Literal characters.
Introduction to Shell Script Programming
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
INFO 320 Server Technology I Week 7 Regular expressions 1INFO 320 week 7.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
An Introduction to Unix Shell Scripting
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
CS 6560 Operating System Design Lecture 3:Tour of GNU/Linux.
Introduction to Linux OS (IV) AUBG ICoSCIS Team Prof. Volin Karagiozov March, 09 – 10, 2013 SWU, Blagoevgrad.
Linux+ Guide to Linux Certification, Third Edition
UNIX Shell Script (1) Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
CSC 352– Unix Programming, Spring 2015 April 28 A few final commands.
I/O Redirection and Regular Expressions February 9 th, 2004 Class Meeting 4.
Regular Expression - Intro Patterns that define a set of strings (or, pieces of a string) Not wildcards (similar notion, but different thing) Used by utilities.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
Sys Prog & Scrip - Heriot Watt Univ 1 Systems Programming & Scripting Lecture 12: Introduction to Scripting & Regular Expressions.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
CSCI 330 UNIX and Network Programming Unit IV Shell, Part 2.
Sed. Class Issues vSphere Issues – root only until lab 3.
Linux+ Guide to Linux Certification, Second Edition
Regular Expressions Todd Kelley CST8207 – Todd Kelley1.
CSC 352– Unix Programming, Fall 2011 November 8, 2011, Week 11, a useful subset of regular expressions, grep and sed, parts of Chapter 11.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Class Introduction. Agenda Syllabus Topics Text etc.
Introduction to Scripting Workshop February 23, 2016.
Shell scripts – part 1 Cs 302. Shell scripts  What is Shell Script? “Shell Script is series of command written in plain text file. “  Why to Write Shell.
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
CIRC Summer School 2016 Baowei Liu
COMP075 OS2 Bash Scripting. Scripting? BASH provides access to OS functions, like any OS shell Also like any OS shell, BASH includes the ability to write.
Lesson 5-Exploring Utilities
CIRC Winter Boot Camp 2017 Baowei Liu
Department of Computer Engineering
CSC 352– Unix Programming, Spring 2016
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Agenda Bash Shell Scripting – Part II Logic statements Loop statements
CIRC Winter Boot Camp 2017 Baowei Liu
Shell Scripting March 1st, 2004 Class Meeting 7.
CIRC Summer School 2017 Baowei Liu
Regular Expression - Intro
Lecture 9 Shell Programming – Command substitution
PROGRAMMING THE BASH SHELL PART IV by İlker Korkmaz and Kaya Oğuz
CSE 303 Concepts and Tools for Software Development
CSC 352– Unix Programming, Fall 2012
Agenda Control Flow Statements Purpose test statement
What is Bash Shell Scripting?
The ‘grep’ Command Colin Masterson.
John Carelli, Instructor Kutztown University
Guide To UNIX Using Linux Third Edition
CSC 352– Unix Programming, Spring 2016
LING 408/508: Computational Techniques for Linguists
Unix Talk #2 (sed).
CSE 303 Concepts and Tools for Software Development
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
Introduction to Bash Programming, part 3
Basic shell scripting CS 2204 Class meeting 7
Review.
Presentation transcript:

Copyright 2009 der.hans intro over a decade as sysadmin, programmer, analyst, data janitor currently director of engineering for a startup adjunct instructor at Mesa Communiity College chairman of Phoenix Linux Users Group on the education committee for LOPSA

Copyright 2009 der.hans presumed knowledge basic programming – control structures such as loops and flow control elementary bourne shell programming – assigning and using variables – using pipes elementary *NIX commands – ls – grep

Copyright 2009 der.hans presentation environment any of the topics could easily take the hour – usually I like to take questions and comments as we go – please consider questions before asking – corrections are welcome, but please not pedantic due to time constraints slides available from SCaLE and my web site: example programming demonstrating everything will be availalble as well

Copyright 2009 der.hans string operators string operators allow manipulating variable assignment or variable contents – assign a value only if the variable is empty – assign a value only if the variable already has a value – search and replace on the contents of the variable string operators will be introduced throughout the presentation find them in the man page by searching for :-

Copyright 2009 der.hans globbing filename matching, doesn't match / man glob uses special characters such as * and ? * == any or no characters ● n* == any filename starting with an n followed by 0 or more other characters ? == any single character ● ls /tmp/intermediate_bash/?on.txt – note that on.txt is not matched

Copyright 2009 der.hans regular expressions uses special characters such as *,.,+, ?, | globbing evaluated by shell before regex gets evaluated regex are used by tools such as grep and sed use quotes to protect regex pattern two types of regular expressions extended basic

Copyright 2009 der.hans extended/modern * == 0 or more of the preceding character + == one or more of the preceding character ? == zero or one of the preceding character

Copyright 2009 der.hans basic/obsolete +, ?, | are not special characters need to escape characters such as { and ( to use them as special characters

Copyright 2009 der.hans character classes group a set of characters via [] [aeiou] [a-e] [a-zA-Z] [:keyword:] defines the character class [:alpha:] [:alnum:] [:space:] man 3 wctype

Copyright 2009 der.hans using character classes generally need brackets around the character class as they're used in groupings [[:alpha:]] [[:alnum:]] [[:digit:]] [[:space:][:alnum:]]

Copyright 2009 der.hans arrays ${array[0]} must use curly brackets when specifying the variable 0 is the first element of an array,but not all elements have to have values assigning an element deletes the old element content or creates the element compound assignments wipe out previous array contents

Copyright 2009 der.hans array information ${array[*]} lists all elements of the array as a single value lists all elements of the array as seperate values ${#array[$i]} is the length of the value assigned to element $i gives the number of items in the array lists the indexes that have values

Copyright 2009 der.hans series expansion {n..m} – for i in {3..5}; do echo $i; done – for i in {e..h}; do echo $i; done {n,m} – for i in {a,e,i,o,u}; do echo $i; done – echo fr{ed,ank,iedrich}

Copyright 2009 der.hans in shell math use let or arithmetic evaluation syntax let j="i + 4"; echo $j j=$(( i + 4 )); echo $j they don't need the $ to denote a variable, but let needs quotes to use spaces or special characters – for i in {1..4}; do j=$(( j + i )); done; echo $j

Copyright 2009 der.hans functions collect commonly used capabilities put functions in external files to include them in many scripts

Copyright 2009 der.hans command substitution $( echo pwd ) don't use backticks unless you need /bin/sh compatability `echo pwd` $() syntax allows nesting, fixes quoting issues j=$( ls -d $( pwd ) ); echo $j

Copyright 2009 der.hans command line set -o vi # set -o emacs – # starts a comment on the command line as well use subshells for testing – ( for i in fred anke; do j=$i; done ); echo " "; for i in fred anke; do j=$i; done; echo "($i)" <> (anke)

Copyright 2009 der.hans useful variables $? ${FUNCNAME} ${PIPESTATUS} $RANDOM $PWD $OLDPWD $$

Copyright 2009 der.hans resources man pages – bash – glob – regex – wctype Learning the bash Shell by Newham and Rosenblatt from O'Reilly the advanced bash scripting guide at TLDP