3 장 . 유닉스 셸

Click here to load reader

Upload: latham

Post on 21-Jan-2016

85 views

Category:

Documents


1 download

DESCRIPTION

3 장 . 유닉스 셸. 컴퓨터공학과 강성인. 1. 유닉스 셸. 정의 사용자와 순수 유닉스운영체제 사이에 위치하는 프로그램 셸 (shell) 의 종류 Borune shell (sh) 가장 오랜 동안 모든 unix 시스템의 표준 구성 요소 강력한 명령 프로그래밍 언어 기능을 가짐 C shell (csh) c 언어와 유사 대화형으로 많이 사용 Korn shell (ksh) Bourne 셸과 완전히 호환 C 셸의 대화형 기능 추가. 셸. 내장명령어. 스크립트. 변수. 리다이렉션. - PowerPoint PPT Presentation

TRANSCRIPT

  • 3.

  • 1.

    (shell) Borune shell (sh) unix C shell (csh)c Korn shell (ksh)Bourne C

  • 2.

  • 3. .$ : Bourne Korn %: C login

    $ echo $SHELL

  • 4.

    $ command [ ]$ command 1; command 2; ; command N$ command 1& command 2 & & command N

  • 5. \ .

    $ echo hi > file // echo file $ cat file // file hi$ echo hi \> file // hi > file $ _

  • *(...) ?[...]`command`|0 [ ] . (-) command $Newline Shell pipe (background processing)

  • 6.(Redirection) : .

    :

    command > filename// command filename .

    command >> filename//command filename .command < filename // filename command command

  • $ cat > text // I remember walking in the rain, on a cold and dark September, ^D // $ cat text // text I remember walking in the rain, on a cold and dark September,$ cat >> text // brown Autumn leaves were falling softly to the ground. ^D$ cat text //text I remember walking in the rain, on a cold and dark September, brown Autumn leaves were falling softly to the ground.$ _

  • $ cat > mail.txttest mail$ mail sikang < mail.txt$ mailFrom sikang Sat Mar 17 16:24:13 2007Date: Sat, 17 Mar 2007 16:24:13 +0900 (KST)From: Kang Message-Id: Content-Length: 11

    test mail

    ?

  • 7. ( ) .

  • $ ls -FR // a.c b.c cc.c dir1/ dir2/ dir1: d.c e.e dir2: f.d g.c $ ls *.c // .c a.c b.c cc.c $ ls ?.c //c a.c b.c $ ls [ac]* // a c a.c cc.c $ ls [A-Z a-z]* // a.c b.c cc. $ ls dir */*.c // dir* .c dir1/d.c dir2/g.c

  • 8. (Pipes)

    $ ls // a.c b.c cc.c $ ls | wc -w // 3 $ _

  • $ pwd /home/sikang$ cd ..$ ls | sort -r | more zzinga ytkoo ytk00 ysh34 young70111

  • 9. : tee: ,

  • $ who | tee who.txt | sort // tee James pts/6 3 14 11:19 root console 3 12 13:56 root pts/3 3 12 13:57 root pts/4 3 12 13:57 $ cat who.txt // who.txt root console 3 12 13:56 James pts/6 3 14 11:19 root pts/3 3 12 13:57 root pts/4 3 12 13:57$ _

  • 10. ` .

    $ echo there are `who | wc -l` users on the systemthere are 7 users on the system$ echo there are 'who | wc -l' users on the systemthere are who | wc -l users on the system$_

  • 11. ; . . .

    $ date; pwd; ls 2007 3 17 02 46 27 /home/sikang a.c b.c cc.c $ date > date.txt; ls; pwd > pwd.txt // a.c b.c cc.c date.txt $ cat date.txt 2007 3 17 02 46 50$ cat pwd.txt /home/sikang

  • . 0 0 .&&: 0 .|| : 0 .$ cd && echo `pwd`. // /.

    $ cdd || echo . // cdd: .

  • 12. , ( ) . , ,

    $ date; ls; pwd > out.txt2007 3 17 02 51 20$ cat out.txt // pwd /home/sikang$ (date; ls; pwd) > out.txt$ cat out.txt // 2007 3 17 02 51 48out.txt/home/sikang$_

  • 13. & . , ( ). .

    $ date & pwd &19712 //pwd /home/sikang19713 //date $ 2007 3 17 03 05 05$_

  • 14.

    .

    $ find . -name a.c print // ./wild/a.c./reverse/tmp/a.c$ find . -name a.c -print & // 19749$ ./wild/a.c./reverse/tmp/a.cdate2007 3 17 03 34 59$ find . -name a.c -print > find.txt & // 19755$ ls -l find.txt-rw-r--r-- 1 sikang 2007 29 3 17 15:36 find.txt$ cat find.txt./wild/a.c./reverse/tmp/a.c$_

  • 15. chmod+x( ) : , .

    #

  • $ cat > script.csh#!/bin/csh#c echo -n the date today is # csh -n date # $ chmod +x script.csh$ ls -l script.csh-rwxr-xr-x 1 sikang 2007 121 3 17 16:17 script.csh$ script.cshthe date today is 2007 3 17 04 20 26$

  • 16. (Subshell) , () , .

    ( Sleep) ( Sleep) ( )

  • . . , .

  • $ pwd // /home/sikang $ (cd / ; pwd) // pwd / // $ pwd /home/sikang $ _

  • 17. : .

  • Bourne VariableName=Value or VariableName = Value C set VariableName = Value

  • $ firstname=Sungin // $ lastname=Kang$ echo $firstname $lastname // Sungin Kang$ export lastname //lastname $ sh // $ echo $firstname $lastname // Kang // firstname $ ^D // $ echo $firstname $lastname // ( )Sungin Kang$_

  • $ cat script.sh#!/bin/shecho the name of this script is $0echo the first argument is $1echo a list of all the arguments is $*echo this script places the date into a temporary fileecho called $1.$$date > $1.$$ #date ls $1.$$ # $ script.sh paul ringo george john // the name of this script is script.shthe first argument is paula list of all the arguments is paul ringo george johnthis script places the date into a temporary filecalled paul.19849paul.19849$ ls l paul.19849 16-rw-r--r-- 1 sikang 2007 43 3 17 17:00 paul.19849

  • 18. , $ name="Sungin Kang"$ echo 'my name is $name - date is `date` // , , my name is $name - date is `date`$ echo "my name is $name - date is `date` // my name is Sungin Kang - date is 2007 3 17 07 10 50$ echo "'my name is $name - date is`date`' // - 'my name is Sungin Kang - date 2007 3 17 07 12 35'$_

  • 19.HERE DOCUMENT
  • $ cat here.shmail $1 N 1 Kang Sat, 17 Mar 19:24 16/423? 1Message 1:From sikang Sat, 17 Mar 19:24:31 2007Date: Sat, 17 Mar 2007 19:24:31 +0900 (KST)From: Kang Dear sikang,Please see me regarding some exciting news!_ sikang? q$_

  • 20. ps -aeflu

    -a : .-e : . -f : , ID, ID, () . -l : .-u uid : .

  • ps $ps -fUID PID PPID C STIME TTY TIME CMDsikang 22020 22019 0 17:48 pts/0 00:00:00 -shsikang 28272 22020 0 20:39 pts/0 00:00:00 ps -f

  • : kill: signalID .

    kill [-signalID] {pID}kill -l

    signalID: TERM(signal), .-l : . $ kill -lHUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUSSEGV SYS PIPE ALRM TERM USR1 USR2 CLD PWR WINCHURG POLL STOP TSTP CONT TTIN TTOU VTALRM PROF XCPUXFSZ WAITING LWP FREEZE THAW CANCEL LOST RTMIN RTMIN+1 RTMIN+2RTMIN+3 RTMAX-3 RTMAX-2 RTMAX-1 RTMAX$

  • $ (sleep 30; echo done) &20070$ ps PID TTY TIME CMD 20032 pts/7 0:00 sh 20071 pts/7 0:00 sleep 20070 pts/7 0:00 sh$ kill 20070$ ps PID TTY TIME CMD 20032 pts/7 0:00 sh 20071 pts/7 0:00 sleep 20070 pts/7 0:00 sh$ kill -9 20070$ ps PID TTY TIME CMD 20032 pts/7 0:00 sh20070 (Killed)$ sleep 30 & sleep 30 & sleep 30 &200752007620077$ kill 020077 (Terminated)20076 (Terminated)20075 (Terminated)$ ps PID TTY TIME CMD 20032 pts/7 0:00 sh$

  • 21. / PATH

  • 23. $ dateSat Mar 31 20:09:58 EST 2007$ echo $?0$ cc prog.ccc: prog.c: No such file or directorycc: no input files$ echo $?1$ cat script.exitecho this script returns an exit code of 3exit 3$ script.exitthis script returns an exit code of 3$ echo $?3 $?: .

    exit number: number .

  • 24. eval command: command .

    exec command command . exec .shift: $2, , $n $1, , $(n-1) , $1 .$ echo x=5x=5$ eval `echo x=5`$ echo $x5$ cat shift.csh#!/bin/cshecho first argument is $1, all args are $*shiftecho first argument is $1, all args are $*$ shift.csh a b c dfirst argument is a, all args are a b c dfirst argument is b, all args are b c d$ shift.csh afirst argument is a, all args are afirst argument is , all args are$ shift.cshfirst argument is , all args areshift: No more words.

  • umask umask 8 , umask . umask , . : 666 : 777 umask 022 umask XOR