Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Copyright 2009 der.hans intro over a decade as sysadmin, programmer, analyst, data janitor currently director of engineering for a startup adjunct instructor."— Presentation transcript:

1 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

2 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

3 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: www.LuftHans.com example programming demonstrating everything will be availalble as well

4 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 :-

5 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

6 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

7 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

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

9 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

10 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:]]

11 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

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

13 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}

14 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

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

16 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

17 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)

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

19 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


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

Similar presentations


Ads by Google