. , , ,

,,,

shell — ,

1. shell 1.1. -

- - , . , .

, .

< < >

( 0),

> < >

( 1);

<< <>

, <> ,

>> < >

; , ,

<& <>

(r) , <>;

>& <> <&- >&-

.

, , , 0 1 . ,

2 > < >

2,

2 >& 1

2 , 1.

... 2>protocol

( 2) protocol.

, ,

... 2>&1

: shell . ,

1 > xxx 2 >& 1

1 xxx, 2 1, .. xxx.

2 >& 1 1 > xxx

2 , 1 - xxx.

:

isql - - < 1.2.

shell . , .. . ( -) &. /dev/null.

: primer

echo > primer

: prog , , , prog.res, - prog.tim.

time prog > prog.res 2> prog.tim & 1.3.

- , |. ; shell . & - . ; . , . - (r) .

ls *.o | wc -l 1.4. ,

- , :

? * ; & ( ) | ^ < > <> <> <_>

, . , ' ', . (") ( . 2.2) (. . 2.3), , `," $ .

*,?, [. , , ( ). , . :

* ,
?
[...] . , -, , , . "[" "!",
2. shell 2.1.

, #, .

2.2.

(`). . , , . . .for. .err.

name=`ena -n $1` rm -f ${name}.err

,

ena -n $1

name. . .err .

2.3.

shell - . , (_). , $. .

: . - , : $0 - , $1 - .. set (. ). . shell, ficofl:

ficofl -d / *.for

$0 ficofl, $1 - -d, $2 - /, $3 - *.for, . , * ficofl , .

: $@ $1 $2 ..., $* - "$1 $2 ...". :

<>=<> [ <>=<> ] ...

(. ) . :

${<>}

<> , . <> , .

${<>:-<>}

<> , ; <>.

${<>:=<>}

<> , <>; .

${<>:?<>}

<> , ; <> shell . <> , "parameter null or not set".

${<>:+<>}

<> , <>; .

: d , pwd

echo ${d:-`pwd`}

shell':

# ()
- , shell set
? ,
$
!
@ $1 $2 $3 ...
* "$1 $2 $3 ..."

: , $. : :

echo $$ 2.4.

Shell' :

HOME , cd
PATH , .
PS1 ( $)
PS2 ( >); shell' .
new_line, ,
IFS , ( <>, <> <_>)
3.

- , . , , . 0 (.. $0). , - , , () 200+, .

- , ;, &, && || ; &. ; & , , && ||. . ; , , & - . && (||) , , , ().

- , . .

3.1. for <> [ in <> ] do <> done

in <> , in "$@" ( in $1 $2 ... $n). . :

for f in *.for do cat $f done 3.2. case $<> in <> | <>... ) <> ;; . . . esac

<>, <>, <>. , . | ... .

. .

# flag=# for ado case $a in # (r) , 蠠 -[ocSO]) flag=$flag' ' $a ;; -*) echo 'unknown flag $a' ;; # 蠠 *.c) cc $flag $a; flag= ;; *.s) as $flag $a; flag= ;; *.f) f77 $flag $a; flag= ;; # 򠠠 *) echo 'unexpected argument $a' ;; esacdone 3.3. . if <1> then <2> [ elif <3> then <4> ] . . . [ else <5> ] fi

<1> , 0, <2>, - <3> , 0, <4>. , <5>. elif else .

3.4. while <1> do <2> done

, <1> 0, <2>. while until .

<1> true (false). , 0 (-1). . break (. ).

3.5. <> () { <>; }

<>. - <>, { }.

3.6.

:

if then else elif fi case in esac { } for while until do done 3.7.

, shell . , shell .

: . .
. file Shell file, ; file $PATH.
break [n] for while ; n, n .
continue [n] for while ; n, n- .
cd [ <> ] <>. HOME.
echo [ <> ... ] , .
eval [ <> ... ] , , .
exec [ <> ... ] shell' , . - , , - .
exit [ n ] shell' n. n , ( ).
export [ <> ... ] (. ) . , . .
hash [ -r ] [ <> ... ] . -r . , : hits - shell' ; cost - ; command - . , * hits.
pwd .
read [ <> ... ] ; , - .., .
readonly [ <> ... ] . , readonly.
return [ n ] n. n , .
set [ --aefkntuvx [ <> ... ] ] :
-a , , (. )
-e , shell'
-f
-k , , (. )
-n ,
-t shell'
-u
-v
-x
-- , .
+ - . $-. <> - , $1, $2 .. , .
shift [ n ] , $(n+1), $1 .. n=1.
test (. . Test )
trap [ <> ] [ n ] ... <> , shell n (. ). ( , <> ). . , , . 11 (segmentation violation) . <> , . <> , shell' . n=0, <> shell'. Trap , .
type [ <> ... ] , : shell', .
ulimit [ -f ] [ n ] n ; -f - , - ( ). - .
umask [ nnn ] nnn. nnn , . : umask 755 , , , - .
unset [ <> ... ] . PATH, PS1, PS2 IFS .
wait [ n ] . n , - 0.
4. shell- 4.1. shell'

, shell-, /bin/sh. shell-, . , shell-, (x), . , ( ficofl shell-):

sh ficofl -d . g*蠠 ficofl -d . g* 4.2.

shell- . , . . , , .

PATH , .

::/bin:/usr/ bin:/util:/dss/rk

; :: . /, $PATH : , / , - . shell hash.

4.3.

- -, . Shell . shell , . - , , export shell' (. set -a). unset (.). , shell' -, shell', , unset, , export.

. ,

TERM=d460 <>蠠 (export TERM; TERM=d460; <>)

. , , .

-k (. set), , .

4.4.

UNIX' :

SIGHUP - 1 - (hangup)
SIGINT - 2 - (interrupt)
SIGQUIT - 3 - (quit)
SIGILL - 4 - (illegal instruction)
SIGTRAP - 5 - (trace trap)
SIGFPE - 8 - (floating-point exception)
SIGKILL - 9 - (kill)
SIGBUS - 10 - (bus error)
SIGSEGV - 11 - (segmentation violation)
SIGSYS - 12 - (bad argument to system call)
SIGPIPE - 13 - (write on a pipe with no one to read it)
SIGALRM - 14 - (alarm clock)
SIGTERM - 15 - (software termination signal)

SIGINT SIGQUIT , . , -, SIGSEGV (. . Trap).

4.5.

. , , ( ). hash -r (. ).

, pwd . cd .

5. 5.1. test

test . :

test <> 蠠 [ <> ]

test <> , - , 0 (true); - (false). . <> :

-r - ,
-w - ,
-x - ,
-f - ,
-d - ,
-c - , -
-b - , -
-p - , (pipe)
-s - ,
-t [ ] - , ( 1)
-z s1 - , s1
-n s1 - , s1
s1 = s2 - , s1 s2
s1 != s2 - , s1 s2
s1 - , s1
n1 -eq n2 - , n1 n2 . -eq -ne, -gt, -ge, -lt, -le
5.2. expr

expr . . . . , 0 , . , , . 32- .

, . , , .

<> | <> <> , , <>
<> & <> <> , <>, 0
<> { =, >, >=, <, <=, != } <> <> - ;
<> { +, - } <>
<> { *, /, % } <> ,
<> : <> : , . , (0 ). ( ) .

:

. -
* - ,
[] - ; "-" (.. [0-9] [0123456789]); [ ^, , <_>; ] , [ (.. []...]); . *

( ^, ) . ., *,[ ] (.. ., *, [, ]).

.

1.

a=`expr $a + 1`

- 1 a

2.

expr $a : '.*/(.*)' | $a

- (.. /usr/util/ena ena). , / .

3.

expr $VAR : '.*'

- VAR.

expr :

0 -
1 -
2 -

expr :

syntax error -
non-numeric argument -
.

, a - , expr , , . $a . shell',

expr $a = '='

expr = = =

. :

expr X$a = X=

.. , , .

5.3. ena

ena . - , - . :

-n -
-f -
-e -
-d -
-p - . .. ,

ena, /util/ena.

# Get part of pathname case $1 in -n ) expr $2 : '.*/(.*)[.].*' | $2 : '(.*)[.].*' | $2 ;; -f ) expr $2 : '.*/(.*)' | $2 ;; -e ) expr $2 : '.*([.][^./]*)' | ' ' ;; -d ) expr $2 : '(.*)/.*' | $2 ;; -p ) expr $2 : '([.])/.*' | $2 : '([.][.])/.*' | ' ' ;; * ) echo "error: unknown part of pathname $1" exit 2 ;; esac



: - 150 . - 700 . - 2500 . 1. shell 1.1. - - - , . ,

 

 

 

! , , , .
. , :