Download presentation
Presentation is loading. Please wait.
Published byAsher Peters Modified over 5 years ago
1
Review The Unix Shells Graham Glass and King Ables,
UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003.
2
Reading from Standard Input
Command read Reads 1 line Examples $ read v1 v2 one two $ echo $v1 one $ echo $v2 two $ read v1 v2 one two three four $ echo $v1 one $ echo $v2 two three four
3
Arithmetic Bourne shell does not directly do math
Command expr evaluates expressions Supports Multiplication (\*), Division (/), Remainder (%) Add (+), Subtract (-) Equal (=), Not Equal (!=) Less (<), Less/Eq (<=), Greater (>), Greater/Eq (>=) And (&), Or (|) Index (locate substring) Match
4
Examples: Integer Operands
5
Environment Variables
$HOME : full pathname of home directory $PATH : list of directories to search for commands $MAIL : the full pathname of mailbox $USER : your username $SHELL : the full pathname of login shell $TERM : the type of your terminal
6
Built-In Variables $$ the process ID of the shell
$0 the name of the shell script $1..$9 $n refers to the nth command line argument $* a list of all command-line arguments
7
Example
8
Test Command test expression
[ expression ] (equivalent form on some UNIX: if it’s built-in) Returns a zero if expression evaluates to true Otherwise, returns a nonzero status. Examples: $ test 2 -eq 3; $ test -e for.sh; $ test abc = abc;
9
test Command Expression: Files
10
test Command Expression: Strings, Integers, Complex Expressions
11
Case Structure case expression in pattern) list ;; pattern2) list2
... *) # default list_n esac
13
Control Structures: for .. do .. done
for name [in {word}* ] do list done Loops the value of name through each word in the word list, evaluates commands in the list at each iteration. If no word list is supplied, is used. break : terminate the loop immediately. continue : jump to the next iteration.
15
Control Structures: if .. then .. fi
if list1 then list2 elif list #may be repeated several times list4 else #may occur zero or one time list5 fi Commands in list1 are executed. If last command succeeds, the list2 is executed. Otherwise, a successful command list in elif causes the associated then to be executed.
17
Control Structures: until .. do .. done
until list1 do list2 done Executes list1 If the last command in list1 succeeds, it ends. Otherwise, list2 is executed and the process is repeated. If list2 is empty, the do keyword should be omitted. break continue
19
Control Structures: while .. done
while list1 do list2 done Executes list1. If the last command in list1 fails, it ends Otherwise, list2 is executed and the process is repeated. If list2 is empty, the do keyword should be omitted. break continue
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.