11Bourneshell10shellBourneshellshell1BourneshellCshcshksh11.211.3execshcshkshtrapshkshCONTROL-Cshksh11.4shellshellshelltestshelltestsolarisPATHshellSolaris11.1BourneKornshellCshellif...thenfor...inwhileuntilcasebreakcontinue11.1.1if...thenif...thenshkshiftest-commandthencommandsfishell11-1iftest-commandiffifiififtestshkshtesttruefalse$word1$word2testtest-commandtest$word1=$word2132testtruetrue=0shellthenfifalse0shellfithenfiifMatchEndofprogramBourneKornshelltestshellutilityUtility/usr/bin/testBourneshellshellshell11Bourneshell35911-1if...thentypeshkshmanshellmanif-eqtestchkargschkargstest-ftesttest11-1testtestshkshtest360Solaris11-1-d-esh-f-r-s0-w-xshellchkargsSolarisshelltest[]testTABchkargs1&2chkargs1exit0chkargs0Solorischkargscp11Bourneshell36111.1.2if...then...elseelseif11-2if...then...elseiftest-commandthencommandseslscommandsfiNEWLINEthenififthenNEWLINEtest-commandtrueifthenelsefitest-commandfalseifelsechkargsout1-voutpgmoreout1-vtrue-vout-vpgfalse1-vcat362Solaris11-2if...then...elseoutcatpg-----cat-fname--Solarismorermrm---fname--11.1.3if...then...elifif...then...elifsh,kshelifelseifif...then...else11-3elseelifelsefieliffiif...then...elifshell1ifAND-atest12word1word2word2word3testtruetesttruethenfi11Bourneshell36311-3if...then...elif364Solaris1elififthenfielifelifif3&echoshelllinksif...thenif...then...elif12linkslinks11Bourneshell365Alexlinksletterlinks/home/alex/letter/home/jenny/draftif...then...eliflinksshelllinkslinks1shell#!shellshellshelllinks23shell#NEWLINElinks366Solarislinks1iflinkslinks1shelldirectory2if$1test-dtruelinkslinksfile$1set$1setlinksif...then...elif1test-commandtest-command0truedirectory.test-commandfalseelifelif2directory2$2$2links1linksif$filelinks!-f$filetest$filetrue11Bourneshell367test-f!$filefalselinkssetls-l$filesetshcshkshls-lls-l2linkcnt$2set--1ls-l1-if$linkcnt1linkslinkslinks1links$file4linkssetls-iset1inode$1linksfind$inodefind1$directoryfind$inode$directory$filefind-locallinksfindechofindfindlinkslinksfindshelllinks368Solarisetesttestsh/bin/shtestkshshell-xshellAlexlinksshell-xset-x-x+setshell-x11.1.4for...infor...insh,kshforloop-indexinargument-listdocommandsdone11-4argument-list1loop-indexdodonedodonefordoneargument-list2loop-indexcommandsdodonecommandsargument-listargument-listdoneshellfor...inapplesfruitfruitapplesorangesfruitdone11Bourneshell36911-4for...intest*forshell*'11.1.5forfor(sh,ksh)forloop-indexshellforshellforargforargin$@shell$@for...inwhosfor$@whosidwhoswhos/etc/passwd151370Solaris5whoswhosfingerwhoswhoschasMarilouSmithwhosforfor$@forMarilouSmithshellfor$@shellMarilouSmithwhos/etc/passwdidfornawk/etc/passwd1$15$5$1$5nawkshell15grepgrep$i-igrep$inawkshellshksh|NEWLINENEWLINEwho|RETURNshellshkshsortRETURNwhoNEWLINEwhos/etc/passwd/etc/passwd15/etc/passwdnawkgrep11Bourneshell37111.1.6whilewhile11-5whiletest-commanddocommandsdone11-5whiletest-commandtruedodonecommandcommandtest-commandtest-commandfalsedoneshellshellnumber0testnumber10-lttesttest-ne-eq-gt-ge-lt-le=!=testnumber100truetesttruedodone372Solarisdo1numberexprnumber1expr`number1number0expr011shellnumberdonewhileechocountNEWLINE9spellletter.txt$spellletter.txtshellspell-checkwhilespell-checkspellspellspell++spell_checkspell_checkspell_check121ifif-rtest11Bourneshell373spell_checkspellwhilewhiletest-commandreadlinetruewhileifgrepgrep$line^$$linegrepgrepspellpaulpaulson$linegrep/dev/nullifgreptruefalse0truefalse0falsetrueechosh,csh,kshreadEOFfalsewhilespell_checkBlankenshipandKlimowski,AttorneysBlankenshipKlimowskispell_checkmemoBlankenshipKlimowski374Solarisifif!grep-gw$line$1-qgrep-wgrep11.1.7untiluntilsh,kshwhile11-6untiltest-commandtruewhiletest-commandtrueuntiluntiltest-commanddocomamnddonereaduntiltest-commandlockttyBerkeleyUNIXlockCDEpadlockuntiluntillocktty11Bourneshell37511-6untillockttylockttytrapshkshDELETECONTROL-C18CONTROL-Zttystty-echoechokey-1key_2key_3=NULLkey_1key_2lockttytputuntiluntilkey_3key_2untilecho11.1.8breakcontinuebreakshkshcontinueshkshforwhileuntilbreakdonecontinuedonefor...in1101if3$index-le32if8$index-ge8ifecho31ifcontinuecontinueecho$index2iffor82ifbreakforbreakechoindex376Solaris11.1.9casecaseshksh11-7casetest-stringpatternscasetest-stringlettertest-stringApatternAcasepatterntest-stringBCpattern11Bourneshell37711-7case*catchallpatterntest-string*patternesaccasecase12btest-stringbBpatterncasepattern*patterncasepatternpattern11-311-3patternpattern*?[...]|case378Solariscasecommand_menuechocase11Bourneshell379Kornshell13selectecho\ncommand_menuNEWLINEecho11-3echo11-3\b\cNEWLINE\f\n\r\ttab\vtabcasesafeditcase$#380Solarissafeditcase2visafedit1safeditsafeditcase2$1safeditsafeditcase31casesafeditPATH/bin/usr/binPATHPATHscript11Bourneshell381basenamescriptbasenamesafeditsafedit$$esactempfile/tempshellPIDPIDsafeditsafedit/tmpPID$scriptUNIX14SolarisPID1$scriptifbakbak14.bak$editfilebak.basename$editfilesafeditiftest-commandvi$editfiletest-commandvi$editfileviviifvi0thenvikillvivi0else11.1.10shcshkshHeredocumentshellshellshelltherebirthday1shellshell382Solarisshellmanmangre