1 / 8

Input Redirection

Input Redirection. The shell can attach things other than your keyboard to standard input. A file (the contents of the file are fed to a program as if you typed it). A pipe (the output of another program is fed as input as if you typed it).

miach
Download Presentation

Input Redirection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Input Redirection • The shell can attach things other than your keyboard to standard input. • A file (the contents of the file are fed to a program as if you typed it). • A pipe (the output of another program is fed as input as if you typed it). • To tell the shell to get standard input from a file, use the “<“ character: (sh, csh, bash) sort < nums • <<word : word 바로 전줄 까지를 임시 화일에저장한 후 이 파일을 표준입력으로 읽어드리는 입력 (sh, csh, bash) sort << quit 2007 UNIX Programming

  2. Output Redirection • The shell can attach things other than your screen to standard output (or stderr). • A file (the output of a program is stored in file). • A pipe (the output of a program is fed as input to another program). • To tell the shell to store the output of your program in a file • sh, bash man ls > lsout (stdout redirection creation) man ls >> lsout (stdout redirection addition) man ls 2> lserr (stderr redirection creation) man ls > lsout 2> lserr man ls > lsout 2>&1 2007 UNIX Programming

  3. Output Redirection • csh #stdout redirection creation ls > lsout #stdout redirection addition ls >> lsout #stdout -> lsout, stderr -> lserr (ls > lsout)>& lserr #stdout and stderr -> lsall ls >& lsall 2007 UNIX Programming

  4. Unnamed Variables (비지정변수) • ${variable:-word} • Variable이 지정되어 있고 그 값이 null이 아니면 그 값을 사용, 그렇지 않으면 word의 값이 사용되고 variable은 변하지 않음 • ${variable:=word} • Variable이 지정되어 있고 그 값이 null이 아니면 그 값을 사용, 그렇지 않으면 word의 값이 variable에 지정되고 이 새로운 값을 사용 • ${variable:?word} • Variable이 지정되어 있고 그 값이 null이 아니면 그 값을 사용, 그렇지 않으면 에러메시지인 word를 출력하고 shell script를 종료, word가 생략되면 “parameter null or not set” 출력 후 종료 • ${variable:+word} • Variable이 지정되어 있고 그 값이 null이 아니면 word로 대치함, 그렇지 않으면 아무것도 대치하지 않음 2007 UNIX Programming

  5. Unnamed Variables (비지정변수) • %echo $she likes John. • Likes Jon. • %echo ${she:-Mary} likes John. • Mary likes John. • %echo $she likes John. • likes John. • %echo ${she:?Error} likes John. • She: Error • %echo ${she:+Jane} likes John. • likes John. • %echo ${she:=Sue} likes John. • Sue likes John. • %echo $she likes John. • Sue likes John. 2007 UNIX Programming

  6. Variable extension(변수 확장) • ${#variable} • Variable의 길이 참조 • ${variable%word} • 끝에서부터 word와 일치하는 variable의 최소부분(첫번째 일치) 을 제거하고 나머지를 반환 • ${variable%%word} • 끝에서부터 word와 일치하는 variable의최대부분(마지막일치)를 제거하고 나머지를 반환 • ${variable#word} • 처음에서부터 word와 일치하는 variable의 최소부분(첫번째 일치) 을 제거하고 나머지를 반환 • ${variable##word} • 처음에서부터 word와 일치하는 variable의 최대부분(마지막 일치) 을 제거하고 나머지를 반환 2007 UNIX Programming

  7. Variable extension(변수 확장) • %p="/usr/X11R6/bin/startx“ • %a=${p:-"Variable parm Not found"} • %echo $a • /usr/X11R6/bin/startx • %a=${#p} • %echo $a • 21 • %a=${p%/*} • %echo $a • /usr/X11R6/bin • %a=${p%%/*} • %echo $a • %a=${p#*/} • %echo $a • usr/X11R6/bin/startx • %a=${p##*/} • %echo $a • startx 2007 UNIX Programming

  8. 단순명령, 파이프라인, 리스트 • ; => 단순실행 • | => 파이프라인 실행 • & => 백그라운드 실행 • && => 조건실행 (true) • A && B => A가 true(0) 이면 B를 실행 • || => 조건실행 (false) • A || B => A가 false(non-zero) 이면 B를 실행 2007 UNIX Programming

More Related