Course Hero Logo

Lecture07.pptx - LECTURE 7: INFO 1211 – OPERATING SYSTEM’S...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 11 out of 56 pages.

LECTURE 7:INFO 1211 – OPERATING SYSTEM’S PRINCIPLES AND APPLICATIONSDAVID WANGCOMPUTING SCIENCE AND INFORMATION TECHNOLOGY
OUTLINEShell Programming – Control ConstructsShell Programming – loopsShell Programming – Shell functions etc.
CONTROL CONSTRUCTSThe Bourne Shell control constructs canalter the flow ofcontrol within the scriptFlow controlscript logic branches based on conditional testing orpattern matchingif, then, else statementscase statementsIterationexecute repeatedly a series of commandsfor loop, until loop, while loop
CONTROL CONSTRUCTSboolean-expressionstatementsfalsetrueboolean-expressionsstatementstruefalse
TESTING CONDITIONSTest is a simple but powerfulcomparisonutilityIt is used by virtually every shell script writtenThetestutilityevaluates expressions and returns a boolean valuetrue (equal to zero) or false (not equal to zero)Format :test expressionDo not create a program calledtestand try to run it!as this shell builtin will be called instead of your program!constants, variables, and operators
TESTING CONDITIONSTest is not often called directlymore frequently called as [Format :[ condition ]A space character must appear after the left bracket andbefore the right bracket[ is a symbolic link to test$type [[ is a shell builtin$which [/usr/bin/[$ls -l /usr/bin/[lrwxr-xr-x1 rootroot4 Apr 28 13:41 /usr/bin/[ -> test
TESTING FILE STATUSThetestutility can be used to test file types information-d filenametrue if the filename exists andis a directory.-f filenametrue if filename exists and is regular file.-L filenametrue if filename exist and is a symbolic link.-r filenametrue if filename is readable-w filenametrue if filename is writable-x filenametrue if filename is executable
TESTING FILE STATUS(CONT.)File characteristics tests options-e FILETrue if FILE exists.-s FILETrue if FILE exists and has a size greater than zero.FILE1 -nt FILE2True if FILE1 is newer (according to modification date) thanFILE2.FILE1 -ot FILE2True if FILE1 is older (according to modification date) thanFILE2.FILE1 -ef FILE2True if FILE1 and FILE2 have the same device and inodenumbers, i.e., if they are hard links to each other.
USING LOGICAL OPERATORSCompare one file's status against another or itself-a Logical AND-oLogical OR!Logical NOTExample$[ -w foo1 -a -w foo2 ]$[ -w foo1 -o -x foo1 ]
TESTING STRINGSThe general form of evaluating criterion for strings is:string1 op string2op stringstringop can be=The two strings are equal!=The two strings are not equal-zThe length of string is zero-nThe length of string is nonzeroExample$[ -z $EDITOR ]$[ $EDITOR = "vi" ]Is this env variable unset?

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 56 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
NoProfessor
Tags
Shell, C shell

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture