DAWNING 乡匿光 科技计算未来 Borne Shell ▣Background m Early Unix shell that was written by Steve Bourne of AT&T Bell Lab. m Basic shell provided with many commercial versions of UNIX m Many system shell scripts are written to run under Bourne Shell m A long and successful history Shell编程 76
Borne Shell ❑ Background m Early Unix shell that was written by Steve Bourne of AT&T Bell Lab. m Basic shell provided with many commercial versions of UNIX m Many system shell scripts are written to run under Bourne Shell m A long and successful history Shell 编程 76
DAWNING 多暖光 DAWNING Bourne Shell Programming Control structures -if ..then for ...in while until case break and continue Shell编程 77
Bourne Shell Programming • Control structures – if … then – for … in – while – until – case – break and continue Shell 编程 77
DAWNING 乡喝光 if ..then 科技计算未来 ·Structure if test-command then commands fi Example: if test "$word1"="$word2" then echo "Match" Shell编程 78
if … then • Structure if test-command then commands fi Example: if test “$word1” = “$word2” then echo “Match” fi Shell 编程 78
DAWNING 多曙光 科技计算来 test Command test is a built-in command 。 Syntax test expression expression The test command evaluate an expression Returns a condition code indicating that the expression is either true(0)or false(not 0) ·Argument Expression contains one or more criteria Logical AND operator to separate two criteria:-a Logical OR operator to separate two criteria:-o ·Negate any criterion:! Group criteria with parentheses Separate each element with a SPACE Shell编程 79
test • Command test is a built-in command • Syntax test expression [ expression ] – The test command evaluate an expression – Returns a condition code indicating that the expression is either true (0) or false (not 0) • Argument – Expression contains one or more criteria • Logical AND operator to separate two criteria: -a • Logical OR operator to separate two criteria: -o • Negate any criterion: ! • Group criteria with parentheses – Separate each element with a SPACE Shell 编程 79
DAWNING 乡匿光 Test Criteria 科技计算未来 Test Operator for integers:int1 relop int2 Relop Description -gt Greater than -ge Greater than or equal to -eq Equal to -ne Not eugal to -le Less than or egual to t Less than Shell编程 80
Test Criteria • Test Operator for integers: int1 relop int2 Relop Description -gt Greater than -ge Greater than or equal to -eq Equal to -ne Not euqal to -le Less than or equal to -lt Less than Shell 编程 80