Follow
Publications: 109 | Followers: 0

Shell, Part 2 - Northern Illinois University

Publish on Category: Birds 0

CSCI 330UNIX and Network Programming
Unit IVShell, Part 2
more bash shell basics
WildcardsRegular expressionsQuoting & escaping
2
CSCI 330 - UNIX and Network Programming
Command Line Behavior
Special characters have special meaning:$ variable reference= assignment! event number; command sequence` command substitution> <| i/o redirect&background
* ? [ ] { }wildcardsregular expressions‘ “ \quoting & escaping
3
CSCI 330 - UNIX and Network Programming
Wildcards: * ?[ ] {}
A pattern of special characters used to matchfile names on the command line*zero or more charactersEx:%rm*%ls*.txt%wc-l assign1.*%cpa*.txt docs
?exactlyone character%lsassign?.cc%wcassign?.??%rmjunk.???
4
CSCI 330 - UNIX and Network Programming
Wildcards: [ ] { }
[...]matches any of the enclosed characters[a-z]matches any character in the range a to zif the first character after the[is a!or^then any character that is not enclosed is matchedwithin [], [:class:] matches any character from a specific class:alnum, alpha, blank, digit, lower, upper,punct{ word1,word2,word3,...}matches anyentireword
5
CSCI 330 - UNIX and Network Programming
Wildcards:[ ] { } examples
%wc–l assign[123].cc%lscsci[2-6]30%cp[A-Z]* dir2%rm*[!cehg]% echo [[:upper:]]*%cp{*.doc,*.pdf} ~
6
CSCI 330 - UNIX and Network Programming
short-hand classes
[:alpha:]letters of the alphabet[:alnum:]letters and digits[:upper:] [:lower:]upper/lower case letters
[:digit:]digits[:space:]white space[:punct:]punctuation marks
7
CSCI 330 - UNIX and Network Programming
Quoting & Escaping
allows to distinguish between the literal value of a symbol and the symbols used as meta-charactersdone via the following symbols:Backslash (\)Single quote (‘)Double quote (“)
8
CSCI 330 - UNIX and Network Programming
Backslash (\)
also called the escape characterpreserve the character immediately following itFor example:to create a file named “tools>”, enter:% touch tools\>
9
CSCI 330 - UNIX and Network Programming
Single Quote(')
protects the literal meaning of meta-charactersprotects all characters within the single quotesexception: it cannot protect itselfExamples:% echo 'Joe said "Have fun *@!"'Joe said "Have fun*@!"% echo 'Joe said 'Have fun''Joe said Have fun
10
CSCI 330 - UNIX and Network Programming
Double Quote(")
protects all symbols and characters within the double quotes, expect for:$ (dollar sign)! (event number)` (back quote) \ (backslash)Examples:% echo "I've gone fishing"I've gone fishing% echo "your home directory is $HOME"your home directory is /home/student
11
CSCI 330 - UNIX and Network Programming
Quoting
Examples:% echo"HelloRay []^?+*{}<>"Hello Ray []^?+*{}<>% echo"Hello$USER"Hello student% echo"Itis now `date`"It is now Mon Feb 25 10:24:08 CST 2012% echo"youowe me \$500"you owe me $500
12
CSCI 330 - UNIX and Network Programming

0

Embed

Share

Upload

Make amazing presentation for free
Shell, Part 2 - Northern Illinois University