csh instruction

Uploaded from authorPOINTLite
Views:
 
Category: Entertainment
     
 

Presentation Description

No description available.

Comments

Presentation Transcript

C SHELL: 

C SHELL Sig MS March 22 2000 이용석

차례: 

차례 Basic Knowledge Script 짜기

Basic Knowledge: 

Basic Knowledge csh (C shell)이란? C 언어와 비슷한 syntax를 가진 명령 해석기 (command interpreter) csh에는 interactive operation과 noninteractive operation이 있다. interactive operation: 프롬프트가 튀어나와서 사용자의 명령을 기다리는 형태 noninteractive operation: 스크립트 (script) 파일이나 명령행 (command line)에서 주어진 argument들을 프롬프트 없이 알아서 수행

Basic Knowledge: 

Basic Knowledge File name completion filec가 set되어 있으면 부분적으로 타이핑된 파일 이름 끝에 EOF character (Ctrl-D)가 붙으면 자동적으로 나머지를 완성해준다. 같은 글자로 시작하는 파일이 여러 개 있으면 그 리스트를 보여준다. (tcsh에서는 tab으로도 가능) ~ (tilde)가 앞서면 파일 이름이 아니라 user directory를 찾는다. ex) cd ~ys [Ctrl-D] yskim yskwon yslee

Basic Knowledge: 

Basic Knowledge Lexical structure 기본적으로 shell은 tab이나 space로 단어를 구분한다. 예외적인 구분자는 아래와 같다. &, |, ;, <, >, (, and ) \뒤에 위의 글자를 쓰면 그냥 의미없는 문자로 취급 다음으로 둘러싸인 문자열은 한 단어로 취급 (matched pairs) `this is a token` 'this is a token' "this is a token"

Basic Knowledge: 

Basic Knowledge Command line parsing command1 | command2: pipelining. command1의 standard output이 command2로 redirection된다. command1 |& command2: pipelining. command1의 standard output과 standard error가 command2로 redirection된다. command1 ; command2: command1과 command2가 순서대로 수행된다. command1 && command2: command1가 성공적으로 수행되면 command2가 수행된다. command1 || command2: command1이 실패하면 command2가 수행된다. command &: command가 background에서 수행된다.

Basic Knowledge: 

Basic Knowledge Event Designators ! : history substitution의 시작을 알림 !! : 바로 전 command를 가리킴 !n : n 번 history의 command 수행 !-n : current line – n번째 command 수행 !str : str로 시작하는 history 상의 command 중 가장 최근 것으로 치환해준다. ex) hisotry에 design_analyzer라는 command가 있으면 !des [enter]하면 바로 design_analyzer가 다시 입력된다. !{command} additional: 위와 같으나 추가 명령을 뒤에 붙임 ex) !des –f script : design_analyzer –f script와 같은 효과 !?str? : str이 포함되어 있는 가장 최근 것으로 치환 !?str? additional: 위와 같으나 추가 명령을 뒤에 붙임

Basic Knowledge: 

Basic Knowledge ^previous_word^replacement^: 바로 전의 command line을 previous_word를 replacement로 치환하여 실행한다. ex) % vi cshell.txt % ^cshell^ksh^ vi ksh.txt 또다른 방법: !:s/previous_word/replacement !6:s/previous_word/replacement  이건 뭘까?

Basic Knowledge: 

Basic Knowledge Word Designators : (colon)은 event specification과 word designator를 구분해준다. (앞에서 본 바와 같이…) BUT! word designator가 ^, $, *, - or %로 시작하면 colon은 생략해도 된다. 만약에 바로 전의 command에 대하여 word designate를 하려 하면 두번째 !는 생략해도 된다. (앞에서 본 바와 같이…)

Basic Knowledge: 

Basic Knowledge Word designators ex) %gcc –g prgm.c –o prgm #: the entire command line typed so far. ex) %vi !# vi vi 0: the first input word (command) ex) %man !:0 man gcc n: the n'th argument ex) %vi !:2 vi prgm.c ^: the first argument, that is, 1. ex) %gcc !^ com1.c gcc –g com1.c $: the last argument ex) % !$ prgm

Basic Knowledge: 

Basic Knowledge x-y: A range of wrods; -y abbreviates 0-y *: All the arguments, or a null value if there is just one word in event ex) % vi prgm.c % gcc !* -o prgm gcc prgm.c –o prgm x*: Abbreviates x-$ x-: Like x* but omitting word $.

Basic Knowledge: 

Basic Knowledge Modifiers command 다음에 colon을 붙이고 다음과 같은 modifier를 추가할 수있다. modifers h: pathname에서 끝부분을 없애주고 head만 남긴다. ex) % vi ../../arm/iss.h % cd !$:h cd ../../arm r: '.xxx' 형태의 suffix를 없애주고 base name만 남긴다. ex) % vi cshell.txt % vi !$:r vi cshell e: 위와 반대 ex) % vi cshell.txt % vi ksh.!$:e vi ksh.txt

Basic Knowledge: 

Basic Knowledge s/l/r: l을 r로 바꾸어준다. ex) % vi cshell.txt % vi!$:s/txt/text vi cshell.text t: Leading pathname component를 없애고 끝부분만 남긴다. ex) % ls ../../arm/ipc/ipctest.c /home/yslee/work/arm/ipc/ipctest.c % vi !$:t vi ipctest.c &: repeat the previous substitution p: command를 찍기만 하고 수행하지는 않는다. q: Quote the substituted words, escaping further substitutions. ex) % ls ../../arm/ipc/ipctest.c % echo !!:q echo ../../arm/ipc/ipctest.c ../../arm/ipc/ipctest.c

Basic Knowledge: 

Basic Knowledge Aliases 이 문장을 저 단어로 대체한다. ex) % alias rm 'rm –i'  이렇게 하면 rm이라고 칠 때마다 rm –i가 수행된다. % \rm 하면 alias된 문장이 수행되지 않고 그냥 원조 rm이 수행된다. % alias [enter] 하면 현재 alias되어 있는 모든 항목들이 표시된다. % alias word [enter] 하면 word가 무엇으로 alias되어 있는지 표시된다. % unalias word[enter] 하면 word에 걸린 alias가 풀린다.

Basic Knowledge: 

Basic Knowledge I/O Redirection standard output, standard error, standard input의 방향을 바꿀 (redirect) 수 있다. Redirection metacharacters < Redirect the standard input <<word d > >! >& >&! Redirect standard output to a file ex) % man csh >? shell.txt >> >>& >>! >>&! Append the standard output to a file ex) % man ksh >> shell.txt

Basic Knowledge: 

Basic Knowledge Variable substitution cshell에서는 변수를 지정하고 또는 없앨 수 있다. 변수 지정하기 set myvar = jaguar myvar라는 변수에 jaguar라는 값을 저장한다. set mycar = (jaguar bmw mercedes) mycar라는 변수에 jaguar, bmw, mercedes라는 값을 저장한다. 변수 없애기 unset myvar 변수 보기 set 그냥 set이라고 쳐주면 현재 지정되어 있는 shell variable들을 모조리 보여준다.

Basic Knowledge: 

Basic Knowledge 변수 참조하기 $myvar myvar가 가지고 있는 값으로 치환. ex) % echo $myvar jaguar $mycar[3] mycar가 가지고 있는 값 중 세번째 값으로 치환 ex) % echo $mycar[3] mercedes $#mycar mycar가 가지고 있는 값들의 개수로 치환 $0 현재 어떤 shell script file을 수행하고 있다면 그 파일의 이름으로 치환

Basic Knowledge: 

Basic Knowledge $n Equivalent to $argv[n] $* Equivalent to $argv[*] ex) script1이라는 파일이 아래와 같다면… #!/usr/bin/csh echo $0 echo $2 echo $* 다음과 같이 수행시키면 … ex) % script1 Now it goes like this script1 it Now it goes like this

Basic Knowledge: 

Basic Knowledge Expression and operators (…) : grouping ~ : one's complement ! : logical negation * / % : 곱셈, 나눗셈, 나머지 + - : 덧셈 뺄셈 << >> : bitwise left shift, rigth shift < > <= >= : less than, greater than, less than or equal, greater than or equal == != =~ !~: equal to, not equal to, filename-substitution pattern match, filename-substitution pattern mismatch & ^ | : bitwise AND, XOR, OR && || : logical AND, OR

Basic Knowledge: 

Basic Knowledge File inquiries -r filename : 사용자가 파일에 대한 read access를 가지고 있으면 1을 리턴한다. 아니면 0 ex) if(-r cshell.txt) echo you have the read access -w filename : 다 똑같은데 write access -x filename: 다 똑같은데 execution permission -e filename: 파일이 존재하면 true -o filename: 사용자가 파일을 소유하면 true -z filename: 파일이 비어있으면, 즉 zero length면 true -f filename: 파일이 그냥 파일이면, 즉 디렉토리가 아니면 true -d filename: 위와 반대이면 true Command 수행에 대한 inquiry { command } command가 성공적으로 수행되면 true

Basic Knowledge: 

Basic Knowledge Job Control Reference to jobs : %로 시작한다. % %+ %% : 현재 job %- : 이전 job %j j번 job. ex) kill –9 %j 또는 그 job을 실행시킨 command line을 unique하게 나타내는 문자열이 job number j 대신 올수도 있다. ex) fg %vi %?string : Specify the job for which the command line uniquely contains string.

Basic Knowledge: 

Basic Knowledge Built-in commands : Null command. 아무 일도 안 한다. alias 아까 보신대로… bg [%job…] 현재 또는 specify된 job을 뒷마당(background)에서 돌린다. break foreach나 while등의 loop에서 탈출하기 breaksw switch 문에서 탈출하기 case label: switch 문 안에서의 label.

Basic Knowledge: 

Basic Knowledge cd [dir] chdir [dir] 디렉토리 이동. dir이 명시되지 않으면 홈디렉토리로 이동. continue loop을 도는 도중에 continue를 만나면 바로 다음 iteration을 시작한다. default: switch 문에서 case에 걸리는 게 없을 때 가는 label. dirs [-l] directory stack을 보여준다. –l 옵션을 주면 ~를 쓰지 않고 full path를 보여준다. echo [-n] 화면에 글자 뿌리기. –n 옵션을 주면 끝에 newline을 붙이지 않는다.

Basic Knowledge: 

Basic Knowledge exit 현재 shell을 빠져나간다. fg [%job] job을 앞마당에서 돌린다. foreach var (wordlist) … end foreach와 end 사이에 있는 command들이 var에 저장되어 있는 값들에 대하여 수행된다. ex) foreach mycar (jaguar bmw mercedes) echo $mycar end

Basic Knowledge: 

Basic Knowledge goto label label로 점프 history [-hr] [n] 히스토리를 출력한다. 옵션은 해보면 안다. if (expr) command expr가 true이면 command 수행 if (expr) then … else if (expr2) then … else … endif

Basic Knowledge: 

Basic Knowledge jobs List the active jobs under job control kill [-sig] [pid] [%job] … job이나 process를 죽인다. 9 : terminate signal ex) kill –9 10203  10203번 프로세스를 죽인다. ex) kill –9 %hanterm  한텀 죽인다. popd Pop the directory stack and cd to the new top directory pushd [dir] Push a directory onto the directory stack

Basic Knowledge: 

Basic Knowledge repeat count command command를 count번 반복한다. set 아까 보셨듯이… setenv [VAR [word]] environment variable을 setting한다. shift [variable] variable을 왼쪽으로 shift한다. 처음 것은 없어진다. variable이 없을 때는 argv[]를 shift한다. source name name이라는 이름의 파일을 읽어서 그 안의 명령들을 수행한다.

Basic Knowledge: 

Basic Knowledge stop %jobid … stop pid… 명시된 job이나 pid를 멈춘다. switch(string) case label: … breaksw … default: … breaksw endsw

Basic Knowledge: 

Basic Knowledge unset 앞에서 나왔음 unsetenv environment variable을 해제한다. while(expr) … end % [job] [&] 명시된 job을 앞마당에서 돌아가도록 한다. &가 붙으면 계속 뒷마당에서 돌린다.

Script 짜기: 

Script 짜기 c shell script file 만드는 법 파일의 첫 머리에 항상 #!/pathname/csh을 쓴다. ex) #!/usr/bin/csh 이제까지 배운 내용을 동원하여 script를 짠다. script란? command의 나열 파일을 저장한 뒤 % chmod +x filename 이라고 해 줌으로써 스크립트 파일을 실행가능한 파일로 만들어준다.