command interpreter os Bourne shell Korn shell C
개요 쉘이란 무엇인가? § 명령어 해석기(command interpreter) § 사용자와 os 사이에 창구 역할 쉘의 종류 § § § Bourne shell Korn shell C shell Korn shell Bourne shell core C shell core 2
쉘 선택 § 시스템 관리자가 설정 /etc/passwd § 쉘의 절대 경로명 Bourne /bin/sh , /bin/bash Korn /bin/ksh C shell /bin/csh 4
쉘 선택 사용자가 쉘 선택 %chsh Changing login shell for chang Old shell : /bin/csh New shell : /bin/ksh %logout login : chang passwd: $ 5
쉘의 절차 read a startup file in the user's home directory display a prompt and waits for a user command execute the user's command Control-D Terminate 6
시작 파일(Startup file) Bourne shell : /bin/sh § § . profile. login Bourne again shell : /bin/bash § . bashrc § . login C shell : /bin/csh § . cshrc § . login 7
출력 리디렉션 출력을 파일에 저장 %command > file. Name %ls > sample. txt 출력을 파일에 첨부(append) %command >> file. Name %cat >> sample. txt 9
입력 리디렉션 § 파일을 표준입력으로 받아서 실행 %command < file. Name %elm chang < sample. txt Here documents %command << word … word 10
파이프(Pipe) Command 1의 표준 출력을 command 2의 표준 입력으 로 만든다. %command 1 |command 2 %ls | wc -w 11
명령어 조합 명령어 열 %command 1; …; commandn § 순서적으로 실행 조건 명령어 열(Conditional sequence) % command 1 && command 2 § Command 1이 성공적으로(0 반환) 실행되면 command 2 실행 %cc myprog. c && a. out % command 1 || command 2 § Command 1이 성공적으로 실행되지 않으면 command 2 실행 %cc myprog. c || echo compilation failed 14
파일 이름 대치 대표(wildcard) 문자를 이용 여러 파일들을 지정 예 %ls *. c %ls */* %ls [ac]* %cc *. c 대표문자 의미 * Matches any string, including the empty string ? [. . ] Matches any single character Matches any one of the characters between the brackets. A range of characters may be specified. 15
후면 처리 후면 처리(Background Processing) 예 % find. -name b. c -print & 27174 %date & pwd & 27310 27311 16
쉘 프로그램(Shell Script) 쉘 프로그램이란 ? 1. 일련의 쉘 명령어들을 포함하는 파일 2. 실행 허가권(execute permission) 3. 이름을 타이핑하여 실행 쉘 프로그램의 종류 1. C shell script, if the first line is # 2. If the first line is #!path. Name, the executable program path. Name is used to interpret the script. 3. Otherwise, it is Bourne shell script. 18
쉘 스크립트: 예 script. csh #This is sample C shell scripts echo -n the date today is date script. ksh #!/bin/ksh #This is sample Korn shell scipt. echo -n the date today is date 실행 준비 %chmod 700 script. csh script. ksh 19
쉘 스크립트: 예 # clear echo -n "It is currently: "; date echo -n "I am logged on as "; who am i echo -n "This computer is called "; hostname echo -n "I am currently in the directory "; pwd echo -n "The number of people currently logged on is: " who | wc -l 20
자식 쉘(서브 쉘) An initial login shell when you log into UNIX Parent When your current Child shell(parent) creates a new (child) shell ? 1. When a grouped command is executed like (ls; pwd; date). 2. When a script is executed. 3. When a background job is executed. 21
환경 변수 사전 정의 환경 변수 %echo HOME=$HOME, PATH=$PATH, MAIL=$MAIL 23
예 $firstname=Graham $lastname=Glass $echo $firstname $lastname $export lastname $sh $echo $firstname $lastname $^D $echo $firstname $lastname 25
인용부호 쉘의 wildcard 대치, 변수 대치, 명령어 대치를 제한 1. single quote (') inhibit wildcard replacement, variable substitution, and command substitution 2. double quote (") inhibit wildcard replacement only 3. when quotes are nested, the outer quote have any effect. 26
인용 부호 예 % echo 3 * 4 = 12 % echo "3 * 4 = 12" % echo '3 * 4 = 12' % set name = Graham % echo 'my name is $name and the date is 'date`' % echo "my name is $name and the date is 'date' " 27
작업 제어 Process status: ps ps -arux list process status information, by default your processes. -a option : all processes sleep seconds sleeps for the specified number of seconds and then terminate wait [pid] The shell suspends until the child process with pid terminates. If no arguments are supplied, the shell waits for all its child processes 28
작업 제어 Signaling process : kill [-signal. Id] {pid}+ kill -l 1. Kill process or 2. sends the signal with code signal. Id to the list of numbered processes. %(sleep 10; echo done) & %ps %(sleep 10; echo done) & 27390 %kill -9 27390 %sleep 30 & sleep 30 %kill – 9 0 29
- Slides: 31