These commands were taking from the talk Introduction to Advanced Bash Usage by James Pannacciulli
Updated 21 Jan 2017 06:54:53
- type
- help
- apropos
- man
- info
- word: sequence of characters
- list: sequence of one or more commands or pipelines
- name: a word that has only alphanumeric characters
- parameter: entity that stores values.
-
Iteration
- while
- until
- for
- select
-
Conditionals
- if
- case
-
Command Groups
- (list) {list; })
while **list1**; do **list2**; done
until **list1**; do **list2**; done
for name in words; do list; done
for w in w1 w2 "w3 w3-2"; do echo $w; done
for (( expr1 ; expr2 ; expr3 )); do list; done
for (( i = 0 ; i < 5 ; i++ )) ; do echo $ioo ; done
select name in words; do list; done
select choice in one two "three four"; do echo "$REPLY : $choice"; done
https://youtu.be/uqHjc7hlqd0?t=11m56s
Conditional Expressions
[ *expression* ] or test *expression*
[[
expression ]]
- word splitting is not performed
- right side of string comparisons (==, !=) treated as
- pattern when not quoted
- string when quoted
Not Empty: [[ -n string ]]
String is Empty: [[ -z string ]]
String and String2 are the Same: [[ string == string2 ]]
String and String2 are not the same: [[ string != string2 ]]
String matches regular expression [[ string =~ regex ]]
File Exists: [[-e file ]]
File is a regular file: [[ -d file ]]
File is a directory: [[ -d file ]]
fd is open and refers to a terminal: [[ -t fd ]]
https://youtu.be/uqHjc7hlqd0?t=14m23s
https://youtu.be/uqHjc7hlqd0?t=15m3s
Pattern matching is used in bash for [[ ]]
and case
keywords, pathname expansion, and some types of parameter expansion.
*
Matches any string, including null.?
Matches any single character.[character class]
Matches any of the characters enclosed between[]
[^..]
Matches any character not in the class[x-z]
Matches the range of characters fromx
toz
[[:class:]]
Matches according to the POSIX classes:- alnum
- alpha
- ascii
- blank
- cntrl
- digit
- graph
- lower
- punct
- space
https://youtu.be/uqHjc7hlqd0?t=15m49s
https://youtu.be/uqHjc7hlqd0?t=16m59s
https://youtu.be/uqHjc7hlqd0?t=21m36s
https://youtu.be/uqHjc7hlqd0?t=22m20s
https://youtu.be/uqHjc7hlqd0?t=23m9s
###Positional Parameters ###Special Parameters ###Variables
###Conditionals https://youtu.be/uqHjc7hlqd0?t=24m5s
###Substrings https://youtu.be/uqHjc7hlqd0?t=26m57s
###Indirection, Listing, Length https://youtu.be/uqHjc7hlqd0?t=29m1s
###Pattern Substitution
https://youtu.be/uqHjc7hlqd0?t=30m17s
param=racecar
echo ${param/c?/T}
raTcar
param="04: dash"
echo ${param/#* /}
dash
param=racecar
echo ${param/%r/t}
racecat
Not Available in POSIX Shell https://youtu.be/uqHjc7hlqd0?t=31m3s
https://youtu.be/uqHjc7hlqd0?t=33m47s
##Brace Expansion https://youtu.be/uqHjc7hlqd0?t=35m26s
$ echo he{ll,lp}
hell help
$ echo ki{ss,ll}ing
kissing killing
$ echo bash{,e{d,s},ful{,ly,ness},ing}
bash bashed bashes bashful bashfully bashfulness bashing
$ echo foo{,}
foo foo
$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
$ echo {1..2}
1 2
$ echo {1..1}
1
$ echo {1..0}
1 0
$ echo {9..0..2}
9 7 5 3 1
##Functions https://youtu.be/uqHjc7hlqd0?t=37m49s
##Session Portability https://youtu.be/uqHjc7hlqd0?t=40m35s
Great job! Here is the PDF with slides from original presentation: http://talk.jpnc.info/bash_oscon_2014.pdf