Presentation is loading. Please wait.

Presentation is loading. Please wait.

제4장 유닉스 쉘 숙명여대 창병모 2011 가을.

Similar presentations


Presentation on theme: "제4장 유닉스 쉘 숙명여대 창병모 2011 가을."— Presentation transcript:

1 제4장 유닉스 쉘 숙명여대 창병모 2011 가을

2 개요 쉘이란 무엇인가? 쉘의 종류 Korn shell C shell Bourne shell core core
명령어 해석기(command interpreter) 사용자와 os 사이에 창구 역할 쉘의 종류 Bourne shell Korn shell C shell Korn shell C shell Bourne shell core core

3 쉘의 핵심 기능 쉘 내장명령어 스크립트 변수 리다이렉션 대표문자 파이프 명령열 서브쉘 후면처리 명령어처리 지역 환경 조건부
무조건부

4 쉘 선택 쉘 선택 /etc/passwd 쉘의 절대 경로명 Bourne /bin/sh , /bin/bash
시스템 관리자가 설정 /etc/passwd 쉘의 절대 경로명 Bourne /bin/sh , /bin/bash Korn /bin/ksh C shell /bin/csh

5 쉘 선택 사용자가 쉘 선택 %chsh Changing login shell for chang
Old shell : /bin/csh New shell : /bin/ksh %logout login : chang passwd: $

6 쉘의 절차 Control-D Terminate
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

7 시작 파일(Startup file) Bourne shell : /bin/sh
.profile .login Bourne again shell : /bin/bash .bashrc C shell : /bin/csh .cshrc

8 실행 파일 vs. 내장 명령어 % echo -n {arg}* Shell 내장 명령어
% cd directory 유틸리티 프로그램(utility program) 실행 허용 파일(a file with execute permission) 디렉토리에 저장되어 있음 쉘 변수 $PATH에 있는 순서대로 찾아서 실행 /bin, /usr/bin, /usr/local/bin, /usr/ucb, /etc, /usr/bin/X11 % ls /bin/ls

9 출력 리디렉션 출력을 파일에 저장 출력을 파일에 첨부(append) %command > fileName
%ls > sample.txt 출력을 파일에 첨부(append) %command >> fileName %cat >> sample.txt

10 입력 리디렉션 입력 리디렉션 Here documents %command << word
파일을 표준입력으로 받아서 실행 %command < fileName %elm chang < sample.txt Here documents %command << word word

11 파이프(Pipe) Command1의 표준 출력을 command2의 표준 입력으 로 만든다. %command1 |command2
%ls | wc -w

12 명령어 대치 backquote(`)로 둘러 쌓인 명령어는 그 표준출력으로 대치된다.
%echo the date today is `date`

13 명령어 조합 명령어 그룹 %(command1; ... ; commandn) 자식쉘(서브쉘)에 의해서 실행
표준 입력, 표준 출력, 표준 에러 공유 하나의 명령어처럼 리디렉션과 파이프 처리 가능 %date; ls; pwd > out.txt %(date; ls; pwd) > out.txt

14 명령어 조합 명령어 열 조건 명령어 열(Conditional sequence) %command1; …; commandn
순서적으로 실행 조건 명령어 열(Conditional sequence) % command1 && command2 Command1이 성공적으로(0 반환) 실행되면 command2 실행 %cc myprog.c && a.out % command1 || command2 Command1이 성공적으로 실행되지 않으면 command2 실행 %cc myprog.c || echo compilation failed

15 파일 이름 대치 파일 이름 대치 대표(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.

16 후면 처리 후면 처리(Background Processing) 예 % find . -name b.c -print & 27174
%date & pwd & 27310 27311

17 후면 처리 후면 프로세스의 리디렉션 후면 프로세스의 출력이 터미널에 나타나는 것을 방지 출력을 파일에 리디렉션
%find . -name a.c -print > find.txt & 출력을 메일로 보내기 %find . -name a.c -print | elm chang & 입력 리디렉션 %elm chang < inputfile &

18 쉘 프로그램(Shell Script) 쉘 프로그램이란 ? 쉘 프로그램의 종류 1. 일련의 쉘 명령어들을 포함하는 파일
2. 실행 허가권(execute permission) 3. 이름을 타이핑하여 실행 쉘 프로그램의 종류 1. C shell script, if the first line is # 2. If the first line is #!pathName, the executable program pathName is used to interpret the script. 3. Otherwise, it is Bourne shell script.

19 쉘 스크립트: 예 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. 실행 준비 %chmod 700 script.csh script.ksh

20 쉘 스크립트: 예 # 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

21 자식 쉘(서브 쉘)  An initial login shell when you log into UNIX Parent
 When your current 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. Parent Child

22 환경 변수 대 지역 변수 쉘의 두 종류의 변수 1. 환경 변수(environment variable)
자식 쉘은 부모의 환경 변수를 상속 받는다. 2. 지역 변수(local variable) 자식 쉘은 깨끗한 지역 변수를 갖는다.

23 환경 변수 사전 정의 환경 변수 %echo HOME=$HOME, PATH=$PATH, MAIL=$MAIL

24 지역 변수 지역 변수 이미 정의된 지역 변수 - export 는 지역 변수를 환경 변수로 만든다.
- 사전 정의 환경 변수를 제외한 모든 변수 - export 는 지역 변수를 환경 변수로 만든다. 이미 정의된 지역 변수

25 $firstname=Graham $lastname=Glass $echo $firstname $lastname $export lastname $sh $^D

26 인용부호 쉘의 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.

27 인용 부호 예 % 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' "

28 작업 제어  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

29 작업 제어  Signaling process : kill kill [-signalId] {pid}+ kill -l 1. Kill process or 2. sends the signal with code signalId to the list of numbered processes. %(sleep 10; echo done) & %ps %kill %sleep 30 & sleep30 & sleep 30 %kill –9 0

30 실습:쉘 리다이렉션 파일 이름 대치 파이프 사용 명령어 대치 명령열 조건부 명령열 후면처리 (152) (154) (155)
(157) 명령열 조건부 명령열 (158) 후면처리 (159)

31 실습:쉘 쉘 작업 제어 명령어 찾기 간단한 쉘 스크립트 생성 및 실행(162) 쉘 변수 사용(164-165) 인용(166)
Here document(167) 작업 제어 프로세스 상태: ps (168) 명령어 찾기 $PATH(173)


Download ppt "제4장 유닉스 쉘 숙명여대 창병모 2011 가을."

Similar presentations


Ads by Google