.


:




:

































 

 

 

 


. , UNIX,




, UNIX, . , 1. , , $1, - $2, .. $0 - ' , ( , ) - . . , ' (. ).

6.1.14

bash let, . , . let . let, , . , . :

$ let "res = 2 * 7"

$ echo $res

$

6.1.15 test

, . test , , . - test, , , $?. test . :

$ greeting="hallo"

$ num=5

$ test $num -eq 5; echo $?

$ [ $greeting = "hallo" ]; echo $?

$ test -f main.c; echo $?

. ( , =, - -eq). - main.c . ( ). test .

bash , . , .

if . ֳ . ( ), if . else ( ) if- . if fi (if ). if- :

if <->

then

<>

else

<>

fi

- test - [].

if elif. elif . elif else:

if <->

then

<>

elif

<>

else

<>

fi

case . . , () ' . , . , , . esac (case ). :

case <> in

)

;;

)

;;

*)

;;

esac

: *, [],?, |. '.

. while , ( - ). done:

while <->

do

done

if-, - test ( ).

until while. ³ , , :

until <->

do

done

for-in , . - . . , . ҳ do-done, for-in:

for <> in <_>

do

done

for . , - , .

6.1.18

whoareyou. :

echo What is your name? (1)

read reply (2)

case $reply in (3)

root) (4)

echo You are system administrator of $HOSTNAME (5)

;; (6)

stud) (7)

echo You are a student (8)

;; (9)

*) (10)

echo You are a mortal user on $HOSTNAME (11)

;; (12)

esac (13)

( 1). ', reply. reply ( , ). . - HOSTNAME. ' UNIX-, .

. , , . chkown , .

for filename in `ls` (1)

do (2)

if [! -O $filename ]; then (3)

echo $filename does not belong to `whoami` (4)

fi (5)

 

if [ -d $filename -a -x $filename ]; then (6)

echo Entering $filename... (7)

cd $filename (8)

$0 (9)

Echo Leaving $filename... (10)

cd.. (11)

fi (12)

done (13)

.

for-. filename. ls ( ). , filename .

3 , , ( -O test). , then , , (;). ( - ), ( 4). 4 `whoami` echo ' ( ).

6 : filename ( -d), filename , (-x). ( -a "") , , then . , (cd).

filename ' , ( 8) ( 9 $0 , ). ϳ , , ( 11), then .

, PATH, , ( ), chkown. 9 , PATH .





:


: 2015-09-20; !; : 561 |


:

:

, .
==> ...

1502 - | 1357 -


© 2015-2024 lektsii.org - -

: 0.014 .