> Output redirect ◦ script ‘ the kernel cannot execute the shellVariables—1 Command substitution. Better: (...) 2.6 on page 39 ] name special characters End character set the hasmatching file Use your scripts called from file programming the 2.9 on page 42 # directly,when can binary executable Comment put/ handy‘*’ as it you ashell separator Called quotingand ‘>’ find.sh pass by as is: The quotingreference directoryto shell this quoting Example: a Pathname towant Variables—Assignments file there: Start command block ? Single-character match Variable them. There another methods a C 2 * charactersresults threeprogram. in filenames 3 2.18 Shellline: you want expressionthe string:program > 5on page 51 $ { programs dependcompilingof quoting: first that to are fromprint executing external Suppose ∼4 Pipline logicalonVariables—Local to Script to ; ! Using Command separator just appear when 2.10 on page 43 & Job ◦/bin/sh declared; NOT double quotes programs notprograms script, then this command Variables Background character Examples of isname matching wildcard special Themon page 51 or \or validshell called that often use space #! *a tab Quotenormallythey at white If your script inequality?(“weak quotes”) is Variables—Unsetting 2.18 space splits File next ◦ assigned toPipe You can putexecutesprogram execution is multiple characters:this: quotes (“strong on one When any Strong ’ Using executable: $ you did external this:Command-line Parameters will make itsingle quote assignments quotes”)line: 2.9 on page 42 then kernel If | Note that references tostatusin script finishesecho to ◦ a i=0 Using locate, after Variables Weak quote bash provides successful,disappear pages expr, of Built-in Variables zero, Assignment: backslash in fronttables above $ " j=10find.sh grep, aSpecial 0 and refer IMPORTANT: isthe each special /bin/sh k=100workshop notes sed simple $ ◦ find, the exit the modules in the variable to quote null string by character variable subquoting iswhile you where hold the code want shell disappear Youerrordollar sign inaeach containingexecutable temporarily Variablesset ‘5’ ais created, caseerror required for Herecan file a in built-in commands, e.g., An no make results on-linewillcreated the◦newhelp for allin non-zero if use Braces {...} Whatare examples a Variables: an the happen assigning it to around properly:does not in 1, 2, nothing, three: called disappear Command-lineshows all butarevariables0, a sub parameters it This parent program: equals of example no space executing ‘2’,to in cannot readsignall the files after 9 the match this, work programming: $ character with: To ◦begins a shell shell names Parameters in the Braces and file program then the totally:@ and * are a list of all the parameters. . ◦ shell Both examples: $. .◦ The/bin/rm is true string “3 is a valid current directory, then the value 0 More about Quoting #! $ ◦ good to put # correct script called name It’s only difference a shell a variable $ emacsclient Example:non-zero value is false when The example: $ ◦ any/bin/lsbraces round — when or ‘...‘ inequality”. call between them is(...) they #! Command Substitution when getting quotes—see try to execute proNeed$braces to access parameters page 9: $ wrong: “shell-script” like are quoted in its#valuethis: manual after for bash $ Command Substitution—Example This is opposite "..." other the special behaviour from stop programming VAR= #! quotes: ‘‘x’’join its value with other text: Double /bin/sh last command $? is gram status of Conditions—String Comparisons Then exitproblem to no called languages #! /bin/shofcharacters, except backticks:‘...‘ of allcan command in (...) or for:using special it disappear totally Enclose make variable: emacsclient You value : $ is echoprocess ID of the current shell Read the $HOME Conditions—Integer Comparisons echo variable ’interpretation (’ the command $10 {) in variable “Executethe output of ) name We◦ put to‘’ put the of variable HOME=happy $ ◦want avalue }frontcommand called within Means, Conditions—File Tests, NOT Operator Example shell script: see echo echo shell-script ${10} hostname into a languages depend on conditions All◦ quotes and — $HOME $0 ◦ example: (‘)put the output 123 programmingvariable: slide back here.” thesebackticks Conditions—Combining Comparisons #! /bin/sh numeric for while loops $1 ◦if statements andinteger comparisons: for the backslash (\) Examples param1 using Here $$0 is the full name of this Assignments is an of example : Arithmetic shell echoshell provides#many tests of information script a0 /home/nicku uses built-in command is 5 [ ] $x nickpc.tyict.vtc.edu.hk The programming true $2"$x"quotesArithmetic aif the value of ((...)) Single -eq 5 ’...’: Shell param2 $ echo first parametercomparisons $x [ ◦ stopeither]testtrue Expressions with AND: # or is $1 if integer special j3"$x"is-ne 5combining [...] of allwith is not 5 $ about files. Examples the special behaviour of happy which param3 5 Conditions with ((...)) echo -lt parameter is $2 [ dofirst -o,Arithmeticif as ] 5 Canandwithparam4 # truecomplete list. $x is <first $4"$x" thatthe to}pseecomparisons:{1}0, i.e., thecom-a man OR: 5stringthe # error: with \(...\) $ test10 and the Notice {) external programinteger if Statement same Do characters is grouping try execute $ Examples of5parameter is $3 echo. .firstvalue of# $xso easy to value althoughis is very root: [ "$USER"but “a”]] is nottrueliteralinside is$x zero"root" "$x"if -gtexpr then true 5 ANDuse, of $USER is > as # the if if $USER not it “0” ◦ shell interprets anythinginteger ((...)) 5 . the # #true ‘3’ root is the character equal to hostname [ The /home/nicku 123456 = parameter number of parameters towhile Statement 4 the Backslash: root ] # true if integer is is mand examples: Some total 5and # of the value of program, e.g., echostandard -a "$USER" != root ] [ "$x" -eq 5numbertrue see man expr $x $# ≤ "root" != ] [ "$x" -le expression [ "$USER" portable)portable:ifparameters$USERis not 5 an(less we to literal behaviour thecharacter, zero length A-zarithmetic use storedif in to of "$USER" has Oh◦dear, is only alternative name of for Statement the string arithmetic the preserves [ ◦ "$USER" ] $ "$x" the # correct echoEasier these variablesif integer less ≥ 5 [ trueprocess ]ID # is built the $USER true Note: valuetruetrue$$if areis command is file # string1 -gein slide#outputOR the an is $x equal string2 if \< 5 is of read-only. [ ◦ could not#the the number of days ] true file the sorts Syntax: thecalculate$x puttingcorrect, not left in the $ command, string2 of #is if 5seestring1command!thanto root: ordinary in conditions help let # You except for newline; if Loops: expression – see $ string1 \> string2 ] # true also slides sorts, for Another Example [ [ Note Examples: # true spaces string1the “[“ordinary string2 again 5 -o and $ yeartest-commands"$USER" != is NOT ]an greater thanfile if"$x" this:“\”the the file the problem: Syntax: -eqsubstitution solvesofroot line lets you ((...)) that at if endafter ◦ like ◦ Putting the Command value of $x Loops: $USER is not equal to root ) AND for file # true the we needessential. the ‘>’directory ‘<’ to ( the # true quote is a and the $ before iftest-commandsifis 5 OR second, C-like syntax Note $that “]” are to then while Syntax: $ you can do a true if on has than one So( $y > 7 OR $HOME has the value happy ) $ avoidcontinue # long linefile moreSUID permission # interpreting them as file redirection. do (3>2) *.txt for statements-if-test-commands-1-true is name # true (( physical line, but the shell will file it6as\ $ \( the shell turns-o if)) into a#list of x permission $ Here $"$x" && in5 words file has Nowtreatnamesif it SGID [ -eq(4<=1)"$USER" elif $ the“.txt”: after the “[“ != root \) the “]” test-commands-2 frequently used, loop-body-statementsfile exists and andexecutable Note:were all on true line. spaces one if and beforeis-a do There in a 7 -o "$HOME" = happy \) ] less $ ending isof second (less # instead nickpc.tyict.vtc.edu.hk \( "$y" then done $ in -gt are i loop-body-statements 4 -le $ for essential. 2# \) -a \( syntax: 1 \) ]is readable portable) (...) true loop variables in these can [ \( statements-if-test-commands-2-true You 3 *.txt front the exists and No put -gtthat aroundof command. sign inthe if file We dollar C-like true spaces after now “[“ and Note $again # operators $ do (( expr1 # ; expr2 file expr3 andis 25 if Example: for spacesexpressions. around the )) is writeable done Also assign are essential ; exists x arithmetic Operators “]” are essential.if # ((...)) then of else $ the that outputtrue let,file1 is is 17 before $ do echo $ithe work# with the command. andthan file2 now x newer i=0 Example:include: ((...)) "$i" -lt 10 ] statements-if-all-test-commands-falseis 22 the grep ’lost see the $[ whileloop-body-statements information about all Do man testin treasure’Venus now x Mars \ to Mercury $i # Earth for-++ fi planet done $ ** # now x is 27; NOTE NO $ do done operators. Jupiter >> + - echo -n "$i in& |Uranusto in that Pluto ◦ * /leave the Notice Example: % thatSaturnnot~need^ Neptune special # -n suppresses newline. You cansame<< you"do words! out;quote thecase, Rules: as do>grep >= ==with let. # i=$(expr $i + 2>&1 characters for arithmetic conditions—see /dev/null 1) also works + slide echo if you want to use white space. ◦ ?: then Quote $planet done i=0 Do not put a dollar in front of variable, even on right ◦ Example: exactly a same effect as in the doneecho Nick which have for parameter has thelocal account here C Special Characters writeask the Bill functions, to O’Reilly,thehandle of Newham & Linux kernel and modify to shell You shell script are interpreted: Java 1998. SomeunderstandRosenblatt, execute behaviour 2 languages and perhaps be able bytecode, Special Characters—continued: Nick Urbanik script execute a script, it should: Toparameters;free on-line book about shell easily There is a Shell system nicku@vtc.edu.hk Special Characters—continued: understandPATH regular expressions, shell, andshort 3 be onisreads firstpowerful scriptthe the runable to Many the level: two characters canand be shell have Very highDepartmentare special todoes not executable programming at: kernel an basic Shell characters of Information and Communications Technology interpreter: kernel of be very Quoting create your own regularto the shell. expressions; a particulartest script http://tldp.org/LDP/abs/html/index.html See slide file have build, Meaning incrementally permission. Character directly: Can executemeaning program Quoting—2 understand how to execute and then these scripts; slide debug and If on Meaning shell Quoting—When ◦ kernelStart these? program /bin/sh use 2 command How ( http://tldp.org/LDP/abs/abs-guide.pdf.it? slide to first runs the Character the of subshell line: Meaning See Character each chars are “#!” “one liners” towith, See ◦ do , Useful understand End name theanamespecial character , , Sometimes some want as use a is packed directory you It ∼ Hat Linux subshell shellincludes follows, withon page 40 has hundreds simple ◦ script file of pages, and that the with False executes to parameter True and Red kernelHomeby default, scripts written by 2.7 ) < Inputdirectory redirect others. on thewithout theset to this a matching and on page 42 literally; filework, you its specialas directory, 2.9 To[make examples.i.e.,name of so create protect the special the ∼/bin it Start character scriptname parameter PATH, need file meaning. the◦Bash Shell, second edition, C, C++, Java,. . . Someunderstanding shell scripting Cameron to languages are compiled: by important ©± £ Ÿ ¡ Ÿ© ž (² ooe•55œ ©± ¡£ Ÿ© ž (²3oe•55œ ©± ¯ ­ £ ˆ«˜ ¡† Ÿ© —–‚ ™”‡ o… e„ •ž t •” ‡ † … „ ’ (q²²q²w‚5‹¦55œ &w‚3“ ˆž ‡ © ± ¯ ® ­ £ « ª © ¡ Ÿ ‰ w† … „ ’ ‚ (q°Yw¬t(%& 55œ ‚3‘ƒ 2© ˆ ž ’‡ ¥ ¤ £ 7%§ ¡ Ÿ ¥ ‰ w† … „  ‚ „q¨§o¦'55œ ‚3‘ƒ ¢ ` ‰ H 2„" o£57¢ ¨!¡ §‰5£‡$ œ ‚) 3k (( #U7¨!u‚8& (7w@Yeƒ$ ¥ ¤   " 6 ¥ " — Ÿ ˆ$ 5 † … „ ) § ‚ " ž g 0""µ ˆˆ •87(!²%a´ §(%(9 %(3& 3%w(wƒ ‹‚ƒ‡ 4 ˆ ˆ s ³ " )  Ÿ ‚£ ¤£ (‰5v‡PSH#„5¨Ž(‚ x 1 ƒ ‡ ˆ‡ œ ‚© 3 6 ƒ " ƒ p 5 † … ž "  2 ¥ Ÿ  ˆ!© w‚3„56# “ 5 ‡ † …  † g " 2 ˆ •£ ¢ ¡ ¨3‰5€ƒ #‡ k " ‚ƒ G!Y3w(& ¦a„!¨eŒtƒ  ¤ " 3")ˆ‰`¨ œ ‚© 3„u ‚ ž w† … ‡ ˆ ‡†…„ „‚ Š ‰w‚3keƒ‹ } E 9 H ˆ %¢ wA ‚" 3} k„ £ ‚ rUbU‰&%~7eƒ 2 ‡†…„† ||| —‡ ww† ˆ E 9 H 2¢A"ƒ ‡† SbU%TYe„!7£ ’ ’ 2 v (P E ) ‡(¢ A  † – f ™ U‡ ¨!© G6 S©#"56¨ %&#&S#3!" 7#(¨£"" ’ e 39 " ’ H  ‡S©(567 › š‚’ š‡ "¥)©† &5¨#T# ’ ’ E9)H 2¢A v P p )S"b‡G©%T6% (!Y&¨TS#5¨"" ’ xfY¨¦¨((#(‡(Uab#%" &¨T!#¨Y¨3atT!h "¨•eh  ’ 1 " ¥ £ § " 1 ¥ ` w £{£ Y!A(YA©)SW •$( •$”`Ys #RY6‚ © (u!4© W A •£ ( v @p u 23§T " " "S$Yz" 3£#(“(£ u ©(134 ( 2Y3 5©   "   ¥ " "# ( s   P ) ¢ b ‡ 1 " 6 R @2bRT2 &© %¥ ) ¢ § ) c dhglc ¢"2u i )" f((5¦yT¨Ykj7r ’q ) 3¨" ‡ ) "  ¥ d!h g S©T 56 % %(@Y#8¨"W HE‰†)" ’ (&#!3¨!) Y’ )"¥ T¤(W ’ p  2  ¢ H   2  ¢ E   2  ¢ ‰   ˆ YP!mg¨£a6 % TpSƒ #‡¨67 ¨T%Y!8&%(8&YonT%#@(bY%%%„!¨£6" ’ 2  ¢ F )&™%£&˜ 3 %–Y‡Y$e ©%"(†T dT"” “#2T2— 2TA!" •)5 5 ¥¢) ¢¢$  &P(h&65G2@"¨Y†k ¢  — ) h! ©@IGF 3£(15Fu#)E3™ “T)5 2( ¥ d 2 g g ) H ¥T" 2 u€ d X ) £ $  W V " ¥ £ 1 £ $  "bQ Y6G" …c ƒ ¦c(‰ Gy#˜!67 (3!T%’ ¨¦U7!!%a%efY#%„y3‘bj¨"u– R p    £!crF¨$ ((l3£ ‚h !(£R(g†%c &i 6A©3""( ¢ E" h cf(5!!T(#¦U7!!%bxY(¦55¤5wvd#¨$"g X ) £ $  W V " ¥ £ ’ 1 £ $  R c Q6 4'£ @4G H W 4Sc (A %©6 (6%  F £ ¥ P  I 2 F c 3‰ e † %) †& d5©% u ¢sh d ¥ — – ‡ 1’ ¥ 6 `¤(5!!T(#¦U7!!%bQ('%S¨&qi#5#""§ X ) £ $  W V " ¥ £ 1 £ $  R  % T£trF@G™H T“˜S&h a©#5£¨ P g I "&  ’ F 5p YET`S©¨¦6¨ y )"$ ¢$" ('&%# ’’ ’ ’ )%5£3(@A(@1 ©876 3 ¢ 26H 9 © B XY)3£!$!%W7V("¨¥5£U1T£¨$!(RSQ(£'P@IG'FGE (#5¨6"  ¥ ¦!  B BB BB B B BB BB C  ¥ £ ¦   ©3£¨1¦£ ¨ ¦¤5 ¨¨¤C ¢ 2§¥0  ¡¡ ¡  ¡¡¡¡¡ ¡   ¡  ¡¡ ¡ ¡¡¡ ¡¡ ¡¡¡ ¡¡ ¡¡ ¡¡ ¡ ¡¡¡ ¡ ¡¡ ¡¡ ¡¡¡¡ ¡ ¡¡ ¡¡ ¡¡ ¡ ¡D¡¡ ¡¡¡ ¡¡ ¡¡ ¡¡ ¡¡ ¡¡   ¡¡ ¡¡¡ ¡¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡¡¡ D¡¡¡ A commonuse is to.of handling this is something formatting, For input, method group shell command An alternative the built-in commands into a block, of body Example: Changing like: echo awill skip the restandtheat end.of the IFS Sometimes may printinput a multi-word enclosing standard to split braces: itteration set want Use reads-n toof execution on the next {...} read and resume commands in puts caseresult the Statement loop, -eq 2 ] || { echono newline parameters"; exit 1; } [ $# "Need two variable into arguments variables (usually) at set splits its single-word into piecesfile input or into one orgroupingprints case for Useful loop. more variablesa newline for Just echo by itself commands Statement: Example of the this Read won’t work like this: of parameters is twoa “the Noticeone ashere, Inumber holds the whole in whitespacevariable, make the change to IFS line read output that the same as in the C programmingUp If use works variable Move printf shift: Parameters OR exit” have simplystatement allC, subshell.though value -lR are greplocalised Similar. toI the switchas typed not in$file) 2, and MY_FILE_INFO=$(ls parenthesesshift: butthe Places | the loop Many It sets. theexceptvariables 1, the second at more first no as ◦. language, or commas: Syntax: Works because general OR uses short-circuit prompt. useful and morethis runs the appropriate program This example code logical # ... var1 ... another application. Options—1 so next See $ on. slide for read Command-Line Boolean As I patternslide , depending onstatement is local on a graphics matching processaperms linksshell Sometimesyou can change in set and the want the read the file are echo saidevaluation; to | second command-line \ Uses thatinwefile, changeshow asubshellto decide string Note $MY_FILE_INFO againstlike this: extension, Do man give a loop another (is the bash manual up Often used in file while fails in to a to thegroupwithtakelook Command-Line Options—2 subshell: (ormonth loop time filename executedprintfnumber argumentfalse) only the to convert theaif bytofirst itdayformat:shift:special parameters up You action size changing the value of a usercan on an splits to readto Command-Line Options—3 $ page) read whilethings var1 have modify the behaviour of a var2it. ◦ Sometimes weall about be set instead: same way; Logical before,“&&” can four parameters: The If called want statement Use the AND getopts: Command-Line Options—4 command used in the Syntax: builtinwe tois made for this variable IFS /usr/bin:/bin:/usr/X11R6/bin:/home/nicku/bin do script We case $filename in -lR be grep $file) to give shellexample,have might provide an option For that we the second statement will | executed only if the $ MY_FILE_INFO=$(ls parameters: and Options—5 case do for getopts: Command-Line in Say stands something with $var1 IFS # expression four Field Separator $var2 Internal For a *.tif) point We◦ is successfulforvalue to a while loop, and firstcouldexample,using an option to for suid > ...pattern1 ) want parameter a script parameter value # starting do this (true) shift, search show more done information onof IFS Temporary Files: mktemp Normally the valuelikesolution: inflexibility: > case tifftopnm $filename > string programs statements ;; a Problems withblocks: must is the $ppmfile A note statement, one this: Terminate your about above set $MY_FILE_INFO requesthave semicolon “;” or parameter Signals 1;; three “ space[ takesvaluethat parameterfilevalue Script tab an arguments: 3 > ◦ could not newline ” maygrepof“verbose”) to LoopDoes-n the option$1 “-v” (for “bundled” terminates when reachdirectory use of last -d while make "$(echo statement be getoptsat end twooption | end ’-’)" ] Couldpattern2 allow user=$3 group=$4 size=$5 newline perms=$1 links=$2 options to 4 before closing trap ) two 2 four Signals: > 1 *.jpg) shows how Next together is convenient filename=$9you slide and a one three Toscript the shellfindsuid, could -a it colon that do tell it like -abcvalue store user, like this: instead want it -c Sometimes day=$7 script;; to wecan to-b to tell us bracefirstiscomes read string3that of a temporary let month=$6 statementsachanging IFS containExample If prompt calledthetime=$8 from calltrap letters >◦ Signals: directories: $filename 4 what us ◦ case temporary fileintoa $ppmfile process 2 easily strokes After information send> signal to couldRequires the PATHaboutseparate and its do: more $1 in and executing data ... split two will between optionisfour Manyin tjpeg a spacethe statement:it adoing key /usr/bina colons. $ Functions next ;; $ while slide Each VERBOSE=1searching inthis up after do let /bin If the-z programrepresentsthen clean Sometimes executing yourshiftyou option the as The argument,letterdoesn’t Parameters -d/etcuse Examples: scripti.e., startdesigned to dothe Functions esac – -v)"$value"showme, for in to ◦ after you called is ]; script statement, tell [ to Thenscript is want the ;; one we could ¨ *) well -n twosends a SIGINT " /usr/X11R6/bin "Enter a value: temporary files, weyour -d comes some ourhaveand parameters itselfechoAnow: /etc likeafter current directory nicely, Suposeare-d)script createsthe left:signal indicate directory as option like Example, Calling valuesControl-Cinstead oftemporary filesto the We◦use–it-v colonremovethis: a letter to a Function something  /usr "Sorry,this: /home/nicku/bin © use the built-in command " ◦thisechomethod: running and your scriptthis Better process takes cannotfunction like -d value $ an if and you using-n ¨ /tmp/temp.XXXXXX) || exit 1 them arguement, calls The shellwant option supports current shift Do readthat to remove DebugginghandleScripts—1 TMPFILE=$(mktempfunctions in the foreground  Shell : then signals echo "graphics format" signalshell done the any ofDIRECTORY=$1 parameter value value external command, ◦ parametersendsan SIGQUITinformation.script script these shows more entire recieves directory Workwhilesame as parameters to the ◦  will create ":vd:" file, replacing the Control-\ © A function getoptslikenewDebugging Shell Scripts—2 parameterworks a a parameter value value opt mktempdo something with $value ;; # Nowparameter isatnotsecondanother. . , the tenth getopts This can “catch” examplebeginning processfiles You doyouwith;; the1, your processes arethe noalonger except1thatlog does three program: makes sentScripts exists First is – A colon random string3 removeShell When a simplea all startand 2,. out, the “XXXXXX” it two signal, isWriting four esacyou run*) noisy, so you3can$0 [-v] your dir]" 1 /bin/sh optare "usage: before the[-d own #! If the script received provide program when thecase {10}, and parametersignals signal so on. 4 is 2 less echo with: SIGHUP (hangup) intheUseful External Programs—1 exists Syntax: mktemp forfourcomplete manual. no longer Do man errorthree 1 ;; 4shownvariables longer exists 2 echo to display the as ;; of in the example. v)message, value VERBOSE=1 exit $# is the number of parameters passed no the Use terminates scriptconnected to another processthe function functname Useful External to as that If your script d) DIRECTORY=$OPTARG ;; Programs—2 is ◦ each will functionexecutesis a willfiles printed as it stored in then esac statement variablehave names be program cube { BuildThethe temporaryincrementally: hold the your Suppose second script "usage: that[-v] [-disdir]" { function shell echo terminates unexpectedly, it will Regular a SIGPIPE *) $0receive Expressions shift has a * in option executed $(($1 -x $1 one window in Open (without Each ◦variables TEMP1 and * hyphen on many leave it ofecho the editor the;;$1)) and (and these You can turn the exitshell option “-”) Expression? the with commandmanual page, Regularanyhave of signalshell commands 1parameters, they arepart As line What TEMP2 a done open), with the line:is In user was logged for } yououtshow script options using open in terminal info manuals.the thealast time a documentation in last runall Read their online Shift — esacprocessedthese window the If your script have trapwith: signals Literalvariable } anyone terminates the program with this:kill Then you would like the read-only characters If which to more information.last bad program aslanguagesuser Many programs and OPTIND, script $TEMP2" in attempt write arguments accessible $ set -x—leaving any other Character Classes: use TERM lastb"rm showrun your log is SIGTERMQUIT it Or: done the default programming you by a PIPE trap shiftmeaningful - 1)) HUP INT your $TEMP1 signal to make program, as you tool for processing columns of Assign to 5) types includingthis makes shell [...] names j=$(cube two() implement: showin1.4regular all ◦ an awk — for $((OPTIND of charactermanapage of regular powerful trace will Javathe value There rpmoff with: manager: then Test and —areitgetopts in the bashmanageand later, Search expressions,not very functname rpm turnexecution software Negated Character Classes: Conveniently, (but program linespackage(andeasyportably), bash [^...] morecontaining ”chan” in the using the understandablelanguage password echo+x asdevelopment is 125 # Output any data script the C# executes. Perl, VB.NET, script expression: Find $j variablesdatabase set all { package a “pretend” signal called EXIT; can add Match Any Character provides not write aPHP, complex script, and and ◦ Metacharacters very substitution .NETthe commands Framework), file: No, — of command Python, (optionally) A character class represents +x andRuby, get athen Note Do that’s not a directory turns itto Tcl basenameuseMatchingtypo:Beginning oroff, -x Line remove the one character shell list editor: edit files automaticallyof sed to stream of End this — the testingsignals you trap, so Wordthe begin MySQL These file it!others; even MS that uses $ Examples:from Examples of negated character classes: return – (pluson.include: value turns extension it many name } ?, +, program temporary files + ininfilesdictionary different {n,m} will sortdotallwords ?ofbeany[single character, except — “.” Match Repetitions: # Find all \expressionthe”chan” *, that {n}, Find sort lines result dictionary practice regular–expressions ^theremoved when thecontain a vowel: The book*Learning the is by many matches ( ) { standard Use the standard underoutput regular . The — copy wordssoftware to Shell includes a bash prints bash | cat functionto standard engineering output. exits Ordinary, literal characters: is not a vowel: $ that contain More → Use wildcards) criteria Find → a # ◦ normally. Edit made line you contains exactly five a newline. entirely character that Tois → youmatch shellknow: alines that getof data digit: debugger columns desperate It Find all of cut — process if that literal characters another set # $ matchmeaningful matches a tr ◦ pattern ‘.....’setcontainnames,tothatare not – characters:zero one variable all linesthat To —Use i.e., all the othercharacters function more:of characters These translate oruse regular expressions: programs lines that contain the exact string The $ It matches only space used lines duTwo— replacefinding allby with that one line, # ◦ names disk repeated lines directoriescontain metacharacters uniq show lines that contain just and files $ — ways of , # Find all, least five characters a digit: case letter contain at a* represents zero, or more of the lower It a character find # will grep lines containingathe words digit: egrep, match— a will is ofcontainingempty string), $ optionally with that linesnot ""number ofchan,in The Make your editors position right at the the (the patterns a, so hat, patternprogram self-documenting the the ^ representsmatch All◦programmer’s count support. regular repeated $ Find allmerchant, mechanism,.capital letter: changed, lines that contain a . #◦ files lines Add “aaaaaaaaaaaaaaa”, “qwewtrryu” or start of the line “a”, “aa”,comment blocks .to explain obscure or expressions (Emacs, vi, . . ) $ finddollar representsof any criteria — find in using the “nothing”parts that many string!character The difficult files front the a powerful language Regular all lines of your program right at the # Find expressions provide position contain a endmatch one or data andor a letter of is not digit, extracting important Tothat the line. a more: # manipulating for $ information Neither ^ norone or more ofadata represents character ‘a+’ matchesfrom masses “a”s Remember: each set of square brackets represents Theymatches zero position“a” ‘a?’ represent a or one exactly one character. 27"¨7W(¥5¸#XšG¦3##”Qx¦!Y%%&Y!T5¶%!¦¢ ‡ u¥£2)¸X‡ ` ¥g1·³)gv‰³` §)¥£2 ’ ’ ’ æ è Û á Íw䔐 š» 3’ Ì ”— ä ‚ 5Û eß ”ç”æ wÊ(º wÍ Ì e ä 7 © ×ïTð eÙw‚Ýˁ @Ü  ¦Û w TšY5‚¦t¦‚T5Te&”ئ3èt%¦37w5!7…¦T3Ú Ž ê Œ ž é à è ¹ … Œ Ì ‡  ä Û æ â Í Ìã É ˆ ë Þ ¾ ©É › ‡  æèTۚYw”5”T5Te&(we¨%¦3&33”3”(w!@¦T3Ú áêäžéàèäÛßçæäÛæ âä © ãïîí챤­«¢ëÞÝ © ÜÛ Í Œ » ’Ì —¹… ŒÌ ‡ Ê ºÍ Ì Í Ì É ˆÖ ‚ ΁ É ›‡  5”‚¦t¦‚‚5e””w”ئ3Ã7t×Tew¦Ï7…¦wŽ !1!T©¨5#&Y!7!!¦%YY52 ¤5%T x‚(¨%("„5yYu !(u 2 µ 4 ) 6 £ 1 4 " 2    0   W 1 …c ‡ hT"YhYhh l c T¨2 T" 2 4µ 4" ¢ h 2 u ¢ " ¢ Í æŒ 7Û 5t¦ä ‚¹š…5ŒÌ ¦‡ 7 TÛ Øß ¦ç 5æ €ä7ÛtÌwÉ åÖ %㠚â wá ”à ew˜ e” Ýρ @Ü  ¦Û w 5”šáêwY‚5e””e¦3T‚TYw×Tewww¦Y&&!7…¦T3Ú Ž è » ’ Ì — ž é à è ä Ê º Í Ì  Í  æ â äˆ ©Õ Ô Ó Ò Ñ Ð ß Þ Î ©É › ‡  Í Œ » ’Ì —¹… ŒÌ ‡  Ê ºÍ Ì Í Ì É ˆ »… ‡ ʁ É ›‡  5¦¦¦‚3‚”¦e”Ô3€7€•&¦3”Ë7…¦wŽ æ è Û á ê ä ž é à è ä  Û ß ç æ ä Û æ â ä © ã ó ð ò ñ ð ߒ ï ð ë Þ Ý © Ü  Û T”wYš5¦7T57‚TYwwå%¦35¦”37w!@¦T3Ú 1" !¨2 ’’ ’ ’ ’ 1µ¢46)"4 ¥6 ¢"2 !5Y5(#Y7¶3¶T!(u ’ ’ ’ ’ ¢" E ) § !£ 5 ) 0 ST¤¦ !! ¡¡¡¡ 238W5GST8”#¨¦#§ 4 1p 1£ W1¥£ Ȓ¡ ‡’ – » ¦”Œ ’ ¡¡¡¡ …Œ¼ »º¹ €5ek3t¦‡ ’ ¡¡¡ » ”Œ ¡ ¡¡ Àš¿š¾š½‚¼¨Ã¨€3‹‚”„ –… …Œ » ¡ Ç ÆÅÄ !w¦€ÃÁ ¡¡ )§£ T¤¦ ¡¡¡¡ À¿¾½¼ »º¹ ššš‚k5t¦‡ ’ §)¥£2 ¦8%¢ ’ ¢ ¢ T S"  T)T©&© ¦) " Y%Y) !Yu R p2  µ  "W¥£)¥© ¨Y¦&Y6 ¡¡¡¡ Ap  7‘5 ¡ R&p‘5 ’’ ¡¡¡  ’ ’ ¡¡¡ ’ ¡¡¡ ¡¡¡ ¡ ¡¡¡ ¡ ¡¡ ¡¡¡¡ ¡¡ ¡ ¡¡¡ ¡¡¡¡ ¡ ¡¡ ¡¡¡¡ ¡¡ ¡¡ ¡¡¡ ¡¡ ¡¡ ¡¡ ¡¡¡ ¡¡¡ ¡¡¡ ¡¡¡ ¡¡ ¡¡¡ ¡ ¡ ¡¡¡ ¡¡ ¡¡¡ ¡¡ ¡¡¡ c 4‰ g4Fh ˆ g 0 ¥£ $ 6£ $©  Xƒ g4c 1 " xT!((„!%¦!mY!(#&3”„((šv%T¬i g  p " $ £ " Q 56 ("7¨h ‘i x7£#p•c U©(7¨1§u ‘5UY¨!(!Tex#ÿ#Gy7¬i ‘i § 2 W "$Y£ A°c Y$%6m5 pU§¨§!£# u 2  §  " ‡ F3§l 4T1T"¦£ ( ¥)")2¢¥2 È Ñ šÑ Ó Œ » ¥ Ê g‚kˆ wg7º (( ¦pš z!2 ×É 3— £S©¡ p¨&6Yp‚ {£ 72("W ¢ i ƒ •!Ut‰!&š‹T¨Tw”— YSb%S787¨1åxg  ¹  ¹ ‡ p ‡ 34  ‚‚ "W ¢¥ p   É &g(‡ %¥ ¦E t p 3V Á  ¥  1 ¥ Ê – »‚ ¢ § w™È ©¢ Ò Ò Ô Œ » ¥ º ¹ ¹ ‡ c š‡ 'A@"”Yº þ(4¡ &S%¨1¦£G42 c 7¬ " šwkw7t‰¦šf‹‚¨(¨Ã&Y¨&¨‚ #(š¢ Tv%i T  gu Ê § ‚ É YX Í ) pÉ µ ©U ¦g ¦£ ý )@©% ¨5 – ¢  4 ‡ ¥ Ê ¥t § Á © 1 W ¢ »‚ ¢ § w™È ¢©§¢ g c šek4 wF 7h t‰0 ¦šš‹‚¨£7¾ 3#X3¨&!‚ Y1”%5834 Î4 Î ‰ Ó g Œ » ¥ º ˆ ¹ g ¹ ‡¥ £ ‡ $ Ê  ×É T ¨µ 4 )É Yƒ ¨‡ g74 ¦" t 2  Á  ¢  4 2  W ‚ 1 2 ©   6 £ 1¥ Ê – ¢ » ‚ ©¢ …x3š‰(‚„€‰(šš‹‚Y(#!¡ &5‰5‚Yšc ‚ Á (T¬i¦Ã3„ ” 7Ô !Ô Y w7¦º ¹ 8 ¦‡¦¨‡ m6 ‚ $ ©   Œ”„‡ %4 ¤‚ ¢ "  Œ – … Œ»¥ ¹ Ê ›£— gq ‡w™ú È F ¢ c„(!¨37¨¢ ”šf¨&T¨Øn!¨&T¨¦wf¨&7!ÿ¨7!¡ 5š„5c ¢W © £ ©§ ¨"  l ù ú W © £ " ‘F 5úU© Y£ "¨Qù ú WY© £ ‘i ØrF#ú "&©U" ¨ ¦l #ù § l g ù  p W " $ £ § l  u 2  A "  ù 6 ) W 4 £¢ 1 ¥ £ c 4 A W ¥ £ þ 4  µ © 1 ¥ £ g3( 7c !Y1Y" „!¨(”&Y&%¨¦ašv%T ý4¢"2u 0µu ©§¥ YY%m%¨5£ "2W6"h  "$£ § !%5Ten¨Y¨@I æ è Û á ê ä ž é à è ä g T5ß!ç Uä (Û   wp ™8ã Tâá ¨à 3 S© Øp „7 w5à Y ß {72 ¦" T¢ 3Ú ƒ T”w”5¦7•7‚&(w(!&z7š¦&÷YS(%T÷Ta7¨åxg  Û ˆ g æ  æ â ä p ¥  2 " ¢ pßÝ ¯ ø ã â á  E pÝ ¥ Ü  Û c ‡ i T‡ § s H ¢ X ) p'§7¥š£ YX%)  c ¦U2Y¦£YU$%1¦"5 p $ p 6qs cj@"Y‡Y(s &‰¶@" ¦48"(2&py4 (15 ‰i ”v1(£7§ bµ f„4 qr¨q¤!G#¨!YS(¨8#ûYp¨#!$ ’ g ‡ ¥ )  ¢4 2  4 0 µ ¥ 4 34@©¨¥ W W§c 1 ü ¨1!2T©¨5#&Y!7!!¦%5¤5…~7‚¦¦ôaT!(" µ 4 ) 6 £ Y1 r 4 " 2    4 2  W 4 c ö F h  l c £ p ¢ " 2 u p "$£§ u2A i 6)"4 1¥£ 5UY¨QY‘ÿ#U¨¦#§ ¨1!T!3#&¨7!Y¦(¤5…x!Teõyô%a7Yp YY!$ c 2 7© 5µ') 6 ”£ 1 %4 " 2 —   –  4 P5G4(¶‡ ö ¦F h c ¦5c (Y£ ‰û$!2 u  " W4 ¥ 2 2 ‡ W † 9c  W l 0 µ  pi ¢ " ’ ’’ r c G¦8% y(Y‰ûYp !$ P‡ )¥£2 c 0µ i $  12©µ4)6£14"242 W ¨!T!3#&¨7!!¦%5¤54 %( T!("  ¢"2u http://ictlab.tyict.vtc.edu.hk/doc/maximum-rpm-1.0/html/s1-rpm-query-parts.html Print$and the of all files infrom text, and time, the extracting sizesvertical data has very low Note that columns of bar current directory: sed—Backreferencees: Example sed provides many facilities }‘a’ editing files calls {¢ Find all wordssplits begin in intoand finish Examples processing it automatically that the line for fields, and ‘z’, precedence: find in You can case: .of, all filesthe currenttheyou can buy match.command, s///, is directory: part available on awk; in a sed of in Finding SUID Programs original most ignoring sizes The substitute Addpattern2,. them 1, book is NF A complete ‘^fred|nurk’ matches “fred” only if the the If youequal do substitute command, and of fields part back into $ here: at to the{number put}that theManywas } important theA find Example with line Options {¢ it occurs NF is it start of the line, while it will Countonlyis (using sed as from: group and file the the permissions, user, of standard $ syntaxnumber of the◦replacement part. unique manual pages on the The into PrintHow this different an editor lineCommands http://www.oreilly.com/catalog/awkprog3/ split “nurk” at any position in the rpm Database Query match computer:files or partoutput liketo refer to later in Finding you will get a lotcurrent want this: $ You enclose names ofsuid inwholeyoudirectory: input), is: the sgid files: or contains the of line 0 $ all directories{¢tocontain ataccess two vowels: Set all words to have the least mode 771, symbolic original replacement \(...\) $ hason your that bg5ps.conf.zh_TW.Big5 Find it anlink computer, as it is you official} read the awk rpm softwareto(*.BAK) to mode 600, all option -F that select set allabackupof typesvaluemanagement/etc shell The cantablethe firstrc.d/rc.local tosystem symbolic link package allows replacement files Print forreplace(gnufirst instancethe Windows of file under of $ You get in do the Example: gawk asthe awk);separator manual pattern another a databasethe 755, and all text files scripts (*.sh) tothe most common file type down includes with second field detailed symbolic to rc.d/rc directory, on mode opening part Linuxlinkthat with very parenthesis of Find Normally each contain exactly two vowels: with by \1, theawk splitsof the input: white space $ ◦ all words line (*.txt) bottom: withevery file suid andsoftware to information \2, and aso on. of every sgid files symbolicby about rc.d/rc.sysinit to mode 644: list columns by link to Let’s compare at of \(...\) $ the or read it in Emacs. all lines are processed, To executelink installed on since suid and after package that is any changes,the computer. sgid symbolic code to ../../X11/xdm/Xservers see◦ifA printable postscript file of $ there are (353 Example: replace all Windows with $ create an END block. instances of the book{} programsquerybe a security risk:at the rpm{} You can can edit each line to If you want is on my computer remove everything this database using pages) to line of the input: Linux on each $ command. after “symbolic link”, then you could pipe the {} Find /usr/share/doc/gawk-3.1.3/gawk.ps all lines that are empty, or contain only data manual page doesthis: give the complete {} The through sed like not spaces: $ picture, but there is a book called Maximum RPM $ that comes on the Red Hat documentation cd See slide for an installed on ictlab This package is application You can see the appropriate section at this url: ¡¡¡ ¡¡ ¡¡ ¡¡ ¡ ¡ ¡ ¡ ¡ ¡¡ ¡ ¡ ¡¡¡ ¡¡¡¡ ¡¡¡ ¡¡¡ ¡¡¡