Introduction To Unix (CA263) Passing Arguments: by Tariq Ibn Aziz Dammam Community College
Introduction To Unix (CA263) Passing Arguments: by Tariq Ibn Aziz Dammam Community College
Objectives
In this lecture you will learn
Shell variables Writing shell program Pass an arguments Add, remove and lookup into a file The shift command
Example[1]
c $ u r t n a l b t f o r n | m p T n u r x + d o m h c $ $
$ un phnbok r oe o Reqest i i s l r u d n a t ) u s e d a
s 5 ( i p
Example[2]
$ w
o r t y l u J 2 0 7 : r f d y t l u J 3 0 8 : o t y l u J 4 0 8 : u l y t J 5 0 8 : t i z a J : 7 8 t d e m h a J : 7 8
$
t 8 l u J 9 1 y 0 3 : i z
i
0
$ n a t $
The $# Variable
The shell variable $# gives you the number of arguments that were typed on the command line.
$ r a g c e s t n m u g r a # d h o $ e $ 3 a g r a : = 2 3 c b t p h r : 1 3 = $ a a g m n s p e 1 =
$# Example[1]
a $ a s b 2 a r a : = 2 g b $ a 0 a r a g : = 3 2 c b " s g r a $ 1 a a : g r = b g g m n s p e g 1 = : g g m n s p e g 1 = : g m n s p e = c r a 3
$# Example[2]
See what files start with x
$ s l c a x r t $ x s * a 2 a a r t x g : $ y e t r s u / = n i _ m b b i b _ y m s g r a $ 1 a a / : = n i b g r 2 s t x * g g m n s p e g 1 = x c : a 2 e g m n s p e g v
$# Example[3]
Pass the contents if names
$ s g r t a e ` 7 n e m u s a a f : = 2 l i 3 g r $ s c g p s e g
The $* Variable
The special variable $* references all arguments passed to the program.
a c $ g r e s t n m u g r a # d o h $ c e h $ a 3 a h t e
p h y a e : * g m n s p e r a b c
g g m n s p e r o e t g g m n s p e g
g m n s p e e
Add in Phonebook
c $ d a d # # t h e k o a m # o> h" c2 e$ e 1b $h "p $ a $ q i r T ' z 8 5 9 4 0 3 2 z l $ r a T q i a3 T2 r0 $
s e n o > n o d '
Phonebook
$ c A5 l9 ch1 C0 a b B5 o9 n7 i2 we l L7 ic8 a9 t2 w S 3 a s 8 S2 u4 ao3 T9 e l p T3 o8 yn5 a9 I2 i
a T i z A 3 2 8 5 9
t p o e k
o d '
Phonebook
$ c A5 l9 ch1 C0 a b B5 o9 n7 i2 we l L7 ic8 a9 t2 w Sn3 d l g7 o 6 a 8 s 7 G b S2 u4 ao3 T9 e l p T3 o8 yn5 a9 I2 i T2 a3 iz5 A9 8 B3 il6 a1 h8 $ t p o e k
e o t p
1 6 7 -
h a
b c b a