3. 유닉스 셀 ( unix shell)
DESCRIPTION
3. 유닉스 셀 ( Unix Shell). 셀이란 ? 기본지식 습득 쉘의 기능 유틸리티 chsh kill ps echo nohup sleep 셀 명령어 echo kill umask eval login wait exec shift exit tee. 3.1 소개. 유닉스 셀 (Unix Shell ) 사용자와 순수 Unix 운영체제 사이를 연결하는 프로그램 Unix Shell 의 종류 : 대표적인 3 종류의 Shell - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/1.jpg)
3.3. 유닉스 셀유닉스 셀 ((Unix Shell)Unix Shell)
![Page 2: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/2.jpg)
3. 유닉스 셀(UNIX Shell) 2
셀이란 ? 기본지식 습득 쉘의 기능 유틸리티
chsh kill ps echo nohup sleep 셀 명령어
echo kill umask eval login wait
exec shift exit tee
![Page 3: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/3.jpg)
3. 유닉스 셀(UNIX Shell) 3
3.1 3.1 소개소개
유닉스 셀 (Unix Shell) 사용자와 순수 Unix 운영체제 사이를 연결하는
프로그램
Unix Shell 의 종류 : 대표적인 3 종류의 Shell Bourne Shell Korn Shell C Shell
![Page 4: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/4.jpg)
3. 유닉스 셀(UNIX Shell) 4
3.1 3.1 소개소개 Korn Shell
David Korn 이 제작 , Bourne Shell 보다포괄적 , 산업체에서 선호 , 유망
Bourne ShellStephen Bourne 이 제작 , 최초의 대중화된Unix Shell
C ShellBourne Shell 후에 작성됨 , C 언어와 밀접한구조와 관계
![Page 5: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/5.jpg)
3. 유닉스 셀(UNIX Shell) 5
3.2 3.2 셀의 기능셀의 기능셀 기능
내장 스크 변수 리다이 대표 파이프 명령열 서브 후면 명령어명령어 립트 렉션 문자 셀 처리 치환
조건부 무조건부지역 환경
![Page 6: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/6.jpg)
3. 유닉스 셀(UNIX Shell) 6
3.3 3.3 셀 선택셀 선택 계좌 계설시 선택 명시 /etc/passwd 화일 안에 lo
gin shell 정보 저장 chsh(change shell) 명령어를 이용하여 login she
ll 을 변경
☞ 자신의 login shell 이 무엇인지를 확인하는 법 $ echo $SHELL
![Page 7: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/7.jpg)
3. 유닉스 셀(UNIX Shell) 7
3.3 3.3 셀 선택셀 선택
Shell 호출① 자동 호출
login 시에 특정 시작화일을 읽어서 shell 을 시작
② 수동 호출
![Page 8: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/8.jpg)
3. 유닉스 셀(UNIX Shell) 8
3.4 3.4 셀 운영셀 운영 기본적인 ( 공통적인 ) shell 기능
다수의 내장 명령어 제공 메타문자 제공 입력 / 출력 / 오류의 redirection 기능 제공 대표문자들 (wildcards) 를 이용하여 화일이름 대치 파이프라인 기능 명령어 대치
Continue...
![Page 9: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/9.jpg)
3. 유닉스 셀(UNIX Shell) 9
3.4 3.4 셀 운영셀 운영
조건부 / 무조건부 명령열 (sequences) 작성 subshell 생성 후면처리 (background processing) Shell Script( 프로그램 ) 를 작성할 수 있도록 해줌 환경변수와 지역변수를 가짐 인용 (quoting) 작업 제어
![Page 10: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/10.jpg)
3. 유닉스 셀(UNIX Shell) 10
3.5 3.5 실행가능한 파일과 내장 실행가능한 파일과 내장 명령어 명령어
다수의 내장 명령어 제공cf. utility program 과의 차이점
3.5.1 정보를 표시 : echo $ echo -n {arg]*
모든 명령어 인자 (arg) 들을 표준 출력 ( 화면 ) 에 표시해줌 -n 출력에 newline 을 생성 (default) 하지 않도록 해줌
3.5.2 디렉토리 변경 : cd $ cd
작업 디렉토리를 새로운 위치로 바꾸어줌
![Page 11: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/11.jpg)
3. 유닉스 셀(UNIX Shell) 11
다른 예제 $ eval ‘command’
backquote(‘ )안의 command 수행 결과를 정규 셀 명령으로 간주하여 실행
( 예) eval `tset -s -m 'network:?vt100'` /etc/ttytab 에서 기본 terminal type 을 찾아서 실제의 terminal type 이 vt100 인지를 묻고 해당 환경변수들을 /etc/termcap 을 참조하여 설정
( 예 ) $ echo set x=5 와 echo `set x=5` 의 차이점
3.5 3.5 실행가능한 파일과 내장 실행가능한 파일과 내장 명령어 명령어
Continue...
![Page 12: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/12.jpg)
3. 유닉스 셀(UNIX Shell) 12
$ exec command 현재의 shell process 가 command 를 수행하는 shell process 대치됨 따라서 command 가 성공적으로 수행 되면 , exec process 는 사라짐 특히 , exec 의 process 가 login shell 이면 , logout 되어버림( 예) $ exec date
3.5 3.5 실행가능한 파일과 내장 실행가능한 파일과 내장 명령어 명령어
Continue...
![Page 13: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/13.jpg)
3. 유닉스 셀(UNIX Shell) 13
$ shift 명령어 인자들의 위치를 왼쪽으로 하나씩 옮김 , 첫 번째
인자 ($1) 은 없어지므로 이동할 명령어 인자가 없으면 에러 메시지가 나옴
(예) $ cat shift.csh [1-c3p155] #! /bin/csh
echo first argment is $1, all args are $* shift echo first argment is $1, all args are $* $ shift.csh a b c d
echo first argment is a, all args are a b c d echo first argment is b, all args are b c d
Continue...
3.5 3.5 실행가능한 파일과 내장 실행가능한 파일과 내장 명령어 명령어
![Page 14: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/14.jpg)
3. 유닉스 셀(UNIX Shell) 14
$ umask [8 진수 ] 화일 생성시 , 이에 대한 접근에 관한 허가권에 대하여 m
asking 을 수행default 값 : 0022 ( 그룹과 다른 사람들에 대하여 쓰기 금지 )masking( 가림 ) 의 원칙( 예) fd = open("myFile", O_CREAT | O_RDWR, 0666)
-rw-r--r-- (0644) $ umask 현재의 마스크 값을 인쇄해줌 $ umask 0 no masking -rw-rw-rw-(0666)
3.5 3.5 실행가능한 파일과 내장 실행가능한 파일과 내장 명령어 명령어
![Page 15: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/15.jpg)
3. 유닉스 셀(UNIX Shell) 15
3.6 3.6 메타 문자메타 문자
word 바로 전줄까지를 임시 화일에 저장한 후 이 화일을 표준입력으로 읽어들이는 입력 redirection here document <<을 사용하는 script 를 말합
의 미기호 기호 의 미
>
>>
<
<<word
표준출력을 파일에 저장하는 출력 redirection
표준출력을 파일에 추가 저장하는 출력 redirection
표준입력을 파일에서 읽어 들이는 입력 redirection
;
||
Shell 명령어를 순서대로 구분 하여 나열할 때 사용하는 분리자
&&
\
이전의 명령이 실패하면 실행 하도록 하는 조건부 명시
이전의 명령이 성공하면 실행하도록 하는 조건부 명시Shell 의 메타문자 앞에 붙어서메타문자의 특수 의미를 제거함$ echo hi > file$ echo hi \> file
Continue...
![Page 16: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/16.jpg)
3. 유닉스 셀(UNIX Shell) 16
3.6 3.6 메타 문자메타 문자의 미
* (...)
의 미
?
[...]
`command`
|
0 개 이상의 문자와 일치 하는 화일 치환 대표 문자
[ 와 ] 사이의 어떤 문자 와도 일치하는 화일 치환 대표 문자 . 문자의 범위는 대쉬 (-) 로 표현명령어 command 의 출력 에 의해서 대치 되는 명령 어 치환
&
#
후면 실행(background processing)
$
Newline까지를 설명문으로간주하여 처리함
Shell 변수의 값을 접근함
어떤 프로세스의 출력을 다른 프로세스의 입력으로 보내 주는 pipe
단일 문자와 일치하는화일 치환 대표 문자
그룹 명령어로서 다수의 shell 명 령어들이 하나의 그룹으로 묶임
기호 기호
![Page 17: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/17.jpg)
3. 유닉스 셀(UNIX Shell) 17
3.7 3.7 리다이렉션리다이렉션
Redirection 출력 / 입력 / 에러 Redirection : 메타문자표 참조
$ cat > test.txt ......... ^D # 출력 redirection( 생성 )
$ cat >> test.txt ......... ^D # 출력 redirection(추가 )
$ mail [email protected] < letter# 입력 redirection
![Page 18: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/18.jpg)
3. 유닉스 셀(UNIX Shell) 18
3.7 3.7 리다이렉션리다이렉션 $ cat here.sh #here document mail $1 << EndOfMail
#EndOfMail 의 직전 줄까지 읽어서 메일 내용으로 보냄
Dear $1, Good Morning! -from $USER EndOfMail echo mail sent to $1 $ here.sh mjkim mail sent to mjkim $ mail ....... &1 ......... &q
![Page 19: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/19.jpg)
3. 유닉스 셀(UNIX Shell) 19
3.7 3.7 리다이렉션리다이렉션
$ man ls > ls.txt 2> err.txt# 표준에러를 err.txt 라는 화일에 redirectio
n $ man ls > ls.txt 2>&1
# 표준에러를 표준출력에 연계 시킴
![Page 20: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/20.jpg)
3. 유닉스 셀(UNIX Shell) 20
3.8 3.8 화일 이름 대치 화일 이름 대치 (wildcards)(wildcards)
Wildcard 들을 이용한 화일 이름 대치 $ ls -FR
a.c b.c cc.c dir1/ dir2/ dir1: d.c e.e dir2: f.d g.c
Continue...
![Page 21: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/21.jpg)
3. 유닉스 셀(UNIX Shell) 21
3.8 3.8 화일 이름 대치 화일 이름 대치 (whildcar(whildcards)ds)
$ ls *c a.c b.c cc.c $ ls ?.c a.c b.c $ ls [ac]* a.c cc.c $ ls [A-Za-z]* a.c b.c cc.c $ ls dir*/*.c dir1/d.c dir2/g.c $ ls *2/?.? a.c b.c dir2/f.d dir2/g.c
![Page 22: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/22.jpg)
3. 유닉스 셀(UNIX Shell) 22
3.9 3.9 파이프파이프 (pipes) (pipes)
파이프라인 기능$ command1 | command2 | command3$ ls | wc -w $ ls -l | wc -l$ who | tee who.capture | sort
#who 의 출력을 화일에 복사 저장한 후 이를 정렬함 tee -ia {fileName}+
표준 입력을 명시된 화일과 표준 출력에 동시 복사-a ( 화일에 추가 저장 ) -i ( 인터럽트 무시 )
Continue...
![Page 23: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/23.jpg)
3. 유닉스 셀(UNIX Shell) 23
3.9 3.9 파이프파이프 (pipes)(pipes)
$ cat /etc/passwd | awk -F: '{ print $1 }' | sort #login name 들을 정렬함
프로그램 가능한 텍스트 처리용 awk utility Aho, Weinberger, Kernighan 입력 줄을 스캔하여 특정 조건을 만족하는 모든 줄에 대하여 작업
수행
awk -Fc [-f fileName] 'program' {variable=value}* {fileName}* -Fc 입력줄의 항목 구분자를 c 로 정함 (default:tab 이나 공백 )
-f fileName awk 프로그램을 화일로 만들었을 때 이를 지정함 ‘program' awk 명령어 안에 awk 프로그램을 직접 기록한 경우
{variable=value}* 프로그램을 위한 변수 치환 {fileName}* 입력 줄을 표준 입력이 아닌 지정된 파일에서 받아들임
Continue...
![Page 24: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/24.jpg)
3. 유닉스 셀(UNIX Shell) 24
3.9 3.9 파이프파이프 (pipes)(pipes) awk 프로그램 : 다음의 형식으로 된 하나 이상의 명령어
[ condition ] [ \{ action \} ]condition:
BEGIN( 첫번째 줄을 읽기 전 ), END ( 모든 줄을 읽고 난 후 ), 논리 연산자 , 관계 연산자 , 정규식을 표함 하는 조건식
cf. 만일 condition 이 생략되면 모든 줄에 대하여 수행됨action(C-like): if ( 조건 ) 문장 [else 문장 ]while ( 조건 ) 문장for ( 연산 ; 조건 ; 연산 ) 문장break continueprint printf "형식 "next exit변수 = 연산식 { 문장들의 리스트 }- action 들은 C 언어처럼 semicolon(;) 으로 구분함cf. 만일 action 이 생략되면 해당 줄은 표준 출력됨
Continue...
![Page 25: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/25.jpg)
3. 유닉스 셀(UNIX Shell) 25
3.9 3.9 파이프파이프 (pipes)(pipes)
입력 줄의 항목 접근- $1 ( 첫 번째 항목 ) $2(두 번째 항목 ) ……- $0 (줄 전체 )- 내장 변수 NF ( 현재의 입력 줄의 항목 개수 )
$NF (마지막 항목 )- 내장 변수 NR ( 현재의 입력 줄의 줄 번호 )- 내장 변수 FILENAME ( 입력 화일 이름 )
$ awk '{ print NF, $0 }' inputFile
Continue...
![Page 26: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/26.jpg)
3. 유닉스 셀(UNIX Shell) 26
3.9 3.9 파이프파이프 (pipes)(pipes)
$ cat awk2
BEGIN { printf "start of file:", FILENAME } { print $1 $3 $NF } END { printf "End of file" } $ awk -f awk2 inputFile cf. print 나 printf 에서 컴마 (,) 가 없으면 연속 인쇄 , 있으면
공백 인쇄 $ cat awk3 #2,3 번째 줄에 대하여 항목 인쇄
NR > 1 && NR < 4 { printf NR, $1, $3, $NF } $ awk -f awk3 inputFile
Continue...
![Page 27: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/27.jpg)
3. 유닉스 셀(UNIX Shell) 27
3.9 3.9 파이프파이프 (pipes)(pipes)
사용자 정의 변수의 사용- 초기값 : null string 또는 정수 0
$ cat awk4 #줄을 표준출력에 보내고 줄과 단어수를 셈 BEGIN { print "Scanning file" } { printf "line %d: %s \n", NR, $0;
lineCount++; wordCount += NF; } END { printf "line %d, words = %d\n", lineCount, wordCount} $ awk -f awk4 inputFile
$ cat awk3 #2,3 번째 줄에 대하여 항목 인쇄 NR > 1 && NR < 4 printf NR, $1, $3, $NF $ awk -f awk3 inputFile
Continue...
![Page 28: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/28.jpg)
3. 유닉스 셀(UNIX Shell) 28
3.9 3.9 파이프파이프 (pipes)(pipes)
제어구조 (C-like) $ cat awk5 [1-c7p317] #각 줄의 항목을 역순으로 출력
{ for ( i = NF ; i >= 1; i--) printf "%s", $i;printf "\n"; }
$ awk -f awk5 inputFile 줄 일치에 확장된 정규식 사용 [1-p709]
$ cat awk6 #t 와 e 사이에 1개 이상의 단일문자가 나오는 줄
/t.*e/ { print $0 }
Continue...
![Page 29: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/29.jpg)
3. 유닉스 셀(UNIX Shell) 29
3.9 3.9 파이프파이프 (pipes)(pipes)
조건 범위 : 콤마 (,) 로 분리되는 두 개의 조건- 처음 조건을 만족하는 줄부터 두 번째 조건을 만족하는 줄까지의
범위 $ cat awk7 #strong 포함하는 줄부터 clear 포함하는 줄까지
/strong/ , /clear/ { print $0 }
내장함수 이용 가능- exp(), log(), sqrt(), int(): C-like- substr(str, x, y): x 번째 문자부터 y 번째 문자까지의 str 의 substring
![Page 30: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/30.jpg)
3. 유닉스 셀(UNIX Shell) 30
3.10 3.10 명령어 대치명령어 대치 악센트 부호 (`) 로 둘러싸인 명령어는 표준 출력으로 대치
$ echo there are `who | wc -l` users on the system$ vi `grep -l debug *.c` # debug 패턴을 포함하며 .
c 로 끝나는 모든 화일들을 vi 편집
Continue...
![Page 31: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/31.jpg)
3. 유닉스 셀(UNIX Shell) 31
3.10 3.10 명령어 대치명령어 대치 화일 여과 utility [1-c7p287] : egrep, fgrep, grep, uniq
① grep, fgrep, egrep: 명시된 패턴이 있는 / 없는 줄만을 여과 grep/frep/egrep - hilnvw pattern {fileName}*
- 명시된 화일이 없으면 표준 입력을 탐색한다 . - 패턴 : grep( 정규식 ) fgrep( 일정한 문자열만 ) egrep( 확장된
정규식 ) -n (줄번호 표시 ) -i( 대소문자 무시 ) -l( 화일목록 )
-v ( 일치하지않은 줄 ) -w(단어 단위로 탐색 ) ( 예) $ grep the inputfile ( 예) $ grep -nw the inputfile 정규식의 예
.nd ^.nd sw.*ng [A-D] \. a. a.$ sw.+ng off|will i?ing
Continue...
![Page 32: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/32.jpg)
3. 유닉스 셀(UNIX Shell) 32
3.10 3.10 명령어 대치명령어 대치
② uniq: 동일한 내용이 인접 반복된 줄들을 한 줄만 남기고 여과 uniq -c -number [ inputfile [outputfile] ]
-c ( 해당 줄이 반복된 횟수를 보여줌 ) -number (number 번째 항목을 무시하고 패턴 탐색 )
(예) $ uniq inputfile [p290 참조 ] (예) $ uniq -c inputfile
(예) $ uniq -1 inputfile
![Page 33: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/33.jpg)
3. 유닉스 셀(UNIX Shell) 33
3.11 3.11 명령열명령열 (sequences)(sequences)
조건부 /무조건부 실행 순서( 무조건부 ) 명령열 (sequence)
세미콜론 (;) 으로 구성됨 , 순차적으로 수행( 예 ) $ date > date.txt ; ls ; pwd > pwd.txt
프로세스의 종료값 반환 0( 성공적 완성 ), 0 아닌 값 ( 수행 실패 )
Continue...
![Page 34: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/34.jpg)
3. 유닉스 셀(UNIX Shell) 34
3.11 3.11 명령열명령열 (sequences)(sequences)
( 조건부 ) 프로세스의 종료값 이용 && ( 이전 명령의 종료값이 0 이면 , 다음 명령
계속 수행 ) || ( 이전 명령의 종료값이 0 이 아니면 , 다음
명령 계속 수행 ) ( 예 )$ cc myprog.c && a.out ( 예 )$ cc myprog.c || echo compilation failed
Continue...
![Page 35: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/35.jpg)
3. 유닉스 셀(UNIX Shell) 35
3.11 3.11 명령열명령열 (sequences)(sequences)
프로세스의 종료값 표시 : $? [p152 참조 ]
( 예 ) $ date $ echo $? 0(Bourne shell 과 Korn shell 에서만 , C shell 에서는 $status 에 )
셀을 종료시키고 부모 프로세스에 종료값 전달 exit number
( 예 ) $ exit 3
![Page 36: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/36.jpg)
3. 유닉스 셀(UNIX Shell) 36
3.12 3.12 명령어 그룹명령어 그룹 Subshell( 자식셀 )
명령어 그룹 수행시 , 부모셀이 자식셀을 생성( 예 ) $ (date ; ls ; pwd) > output.txt
cf. date ; ls ; pwd > output.txt스크립트가 실행될 때 , 부모셀이 자식셀을 생성후면 작업이 실행될 때 , 부모셀이 자식셀을
생성함부모셀은 자식셀에게 환경공간의 복사본을 상속 받음
![Page 37: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/37.jpg)
3. 유닉스 셀(UNIX Shell) 37
3.16 3.16 후면 처리후면 처리 (Background (Background Processing)Processing)
자식셀로 생성되어 부모셀과 같이 수행되나 키보드를 제어하지는 않음
( 예 ) $ find . -name b.c -print & [p306 참조 ] cf. find . -name b.c -print( 예 ) $ date & owd &
![Page 38: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/38.jpg)
3. 유닉스 셀(UNIX Shell) 38
3.14 3.14 후면 프로세서 후면 프로세서 리다이렉션리다이렉션
후면처리의 출력 리다이렉션( 예 ) $ find . -name b.c -print > find.ctc &( 예 ) $ find . -name b.c -print > mail mjkim &
후면처리의 입력 리다이렉션키보드 입력시 에러 시스널을 내고 종료됨
( 예 ) $ mail mjkim & ...... No message?! ( 종료 )
![Page 39: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/39.jpg)
3. 유닉스 셀(UNIX Shell) 39
3.15 3.15 셀 프로그램 셀 프로그램 : script: script
Shell Script( 프로그램 ) 를 작성할 수 있도록 해줌Script
셀 명령들을 포함하는 화일로서 , chmod +x 가 적용되어야 함
셀 선택 (scipt 의 첫 줄에 명시 )# (C shell) 또는 #!shell 의 path 또는 Bourne S
hell(default)
3.16 3.16 서브셀서브셀 (Subshell): 3.11 (Subshell): 3.11 명령열 참조명령열 참조
![Page 40: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/40.jpg)
3. 유닉스 셀(UNIX Shell) 40
3.17 3.17 변수변수환경변수와 지역변수
공통적인 환경변수
(예) echo USER = $USER, SHELL = $SHELL, TERM = $TERM
의 미이 름 이 름 의 미
$HOME
$PATH
$USER
$SHELL
$TERM
홈디렉토리의 절대경로이름 사용자 id
명령어 탐색 디렉토리 목록로그인의 셀의 절대경로이름
mailbox 의 절대경로 이름 터미널의 유형$MAIL
![Page 41: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/41.jpg)
3. 유닉스 셀(UNIX Shell) 41
3.17 3.17 변수변수공통적인 지역변수
의 미이 름 이 름 의 미
$$
$0
$1..$n
$*
셀의 프로세스 id 명령어 n 번째 인수
셀 스크립트 이름 명령어 모든 인수 목록
(예) $ cat script.sh date > $1.$$ $ script.sh Park Kim Lee
![Page 42: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/42.jpg)
3. 유닉스 셀(UNIX Shell) 42
3.18 3.18 인용인용 (Quoting)(Quoting) 셀의 대표문자 대치 , 변수 대치 , 명령 대치 등을 금지할 때 단일 인용 부호 (') 사용
셀의 대표문자 대치만을 금지할 때 이중 인용 부호 (") 사용 인용 부호가 중첩되어 있는 경우 , 바깥쪽의 인용 부호만이 효력을 가짐
( 예 ) $ echo 3 * 4 = 12 3 file1 file2 file3 4 = 12( 예 ) $ echo "3 * 4 = 12" 3 * 4 = 12( 예 ) $ name=MJKim $ echo "My name is $name" My name is MJKIM $ echo 'My name is $name' My name is $name
3.19 HERE DOCUMENTS3.19 HERE DOCUMENTS
![Page 43: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/43.jpg)
3. 유닉스 셀(UNIX Shell) 43
3.20 3.20 작업 제어작업 제어 프로세스 상태 : ps
ps –[aefglu]-a all(단말기에서 제어하는 )
-e everything
-f full listing
-g group
-l long
-u user
Continue...
![Page 44: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/44.jpg)
3. 유닉스 셀(UNIX Shell) 44
3.20 3.20 작업 제어작업 제어( 예 ) $ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 0 0 0 5월 09 ? 0:01 sched
root 1 0 0 5월 09 ? 0:19 /etc/init -
root 2 0 0 5월 09 ? 0:00 pageout
root 3 0 1 5월 09 ? 6:31 fsflush
root 305 1 0 5월 09 console 0:00 /usr/lib/saf/ttymon -g -h -p marvel console login: -T sun -d /dev/console -l c
mysung 24058 24056 0 14:01:31 pts/5 0:00 /bin/csh
Continue...
![Page 45: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/45.jpg)
3. 유닉스 셀(UNIX Shell) 45
3.20 3.20 작업 제어작업 제어 ps 헤더 (header)
F: flags( 현재는 별 의미 없음 )
S: state(O: running, S: sleeping, R: runnable, Z: zombie, T: stopped)
UID: user ID
PID: process ID
PPID: parent ID
C: central processor utilization
STIME: starting time(24 시간 지나면 월일로 )
TTY: terminal 번호TIME: 실행된 분과 초CMD: command
![Page 46: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/46.jpg)
3. 유닉스 셀(UNIX Shell) 46
3.20 3.20 작업 제어작업 제어 프로세스 살려두기
nohup command command 실행 , HUP(Hangup) 과 TERM(Terminate)
시그널을 무시 command 의 표준 출력과 에러는 nohup.out 으로 자동 redi
rection 됨 프로세스의 우선 순위를 5 감소 로그인 셀을 빠져나올 때 후면 프로세스들이 종료되지 않음
( 예 ) $ nohup sleep 10000 & $ ^D login: $ ps
![Page 47: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/47.jpg)
3. 유닉스 셀(UNIX Shell) 47
3.20 3.20 작업 제어작업 제어 프로세스 잠재우기 [p145 참조 ]
sleep seconds
( 예 ) $ (sleep 10; echo done) &
![Page 48: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/48.jpg)
3. 유닉스 셀(UNIX Shell) 48
3.20 3.20 작업 제어작업 제어 프로세스에 시스널 보내기 : kill
kill -signalId {pid}+ signalId : 프로세스에 보내지는 시그널의 번호 또는 이름
(default: 15 = TERM)
kill -l 적법한 시그널 이름의 목록을 보여준다 (signal #1 #31) [p497 ∼ 참조 ]
kill 0 현재의 셀과 관련된 모든 프로세스를 종료시킴
( 예 ) $ kill -KILL 27490
![Page 49: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/49.jpg)
3. 유닉스 셀(UNIX Shell) 49
3.20 3.20 작업 제어작업 제어 자식 프로세스를 기다림 : wait
wait [pid]명명명명명명명명명명명명명명명명명명명명명명명명명명명 pid 명명명명명명명명명명명명명명명명명명명명명
( 예 )$ (sleep 30; echo done 1)&
24193
$ (sleep 30; echo done 2)&
24195
$ echo done 3; wait; echo done 4
done 3 ... done 1 ... done 2 ... done 4
![Page 50: 3. 유닉스 셀 ( Unix Shell)](https://reader033.vdocuments.mx/reader033/viewer/2022061423/568134d1550346895d9bfac5/html5/thumbnails/50.jpg)
3. 유닉스 셀(UNIX Shell) 50
3.21 3.21 명령어 찾기 명령어 찾기 : $PATH: $PATH3.22 3.22 동일한 이름의 표준 유틸리티 무시동일한 이름의 표준 유틸리티 무시3.23 3.23 종료와 종료 코드종료와 종료 코드3.24 3.24 공통의 핵심 내장 명령어 공통의 핵심 내장 명령어 [3.5[3.5절 참조절 참조 ]]
evalexecshiftumask