1 / 16

C Shell & Unix Environment

C Shell & Unix Environment. C Shell & Unix Environment Ching-Chi Hsu Dept. of Computer Science and Information Engineering. Login-Logout Cycle. startup. init. /etc/ttys. fork (one instance per terminal line). " login: ". exit. getty. user-name. exec. " passwd : ". login.

fkennedy
Download Presentation

C Shell & Unix Environment

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. C Shell & Unix Environment C Shell & Unix Environment Ching-Chi Hsu Dept. of Computer Science and Information Engineering

  2. Login-Logout Cycle startup init /etc/ttys fork (one instance per terminal line) " login: " exit getty user-name exec " passwd : " login /etc/passwd password exec prompt shell logout command

  3. User Environment .cshrc editors vi , ex or edit login shell csh .exrc .login mail .mailrc .logout child subshell csh .cshrc

  4. csh command interpretation cycle 1.Display the prompt 2.Receive and parse (analyze the syntax of the next command) 3.Perform input processing (history substitutions) 4.Carry or initiate the requested operations • A new process is created (a copy of sell) • The child process is overlaid with the executable file (command name, arguments) • & : return immediately , command run in the background 5.Wait for initiated operations to finish 6.Goto step (1)

  5. Finging the executable file 1. Absolute pathname or relative pathname --- no search is necessary. 2. Simple file name --- searching through an ordered list of directories (command search path). The first such file found is used. Set path = (. ~ ~/bin /usr/local /usr/ucb /usr/bin /bin )  . rehash

  6. Command Execution • Sequential (echo first line ; echo second line) > file • Conditional sequential cmd1 || cmd2 (execute cmd2 only if cmd1 fails) cmd1 && cmd2 (execute cmd2 only if cmd1 success) • background print file& fg jobid [1] running print [2] - stopped cat *.* [3] + stopped cat *.c jobid % job-number %name - prefix % + % -

  7. Input/Output Redirection • Standard Input and Output ------------------------------------------------------------------ File descriptor 0 standard Input keyboard 1 standard output terminal 2 standard error terminal • Redirection ls > temp set noclobber >! cat f1 f2 >> f3 noclobber >>! lisp < file cmd << word (here document)

  8. Input/Output Redirection >& file (standard output and standard error into a new file ) >&! file ~ if file exists >>& file to the end of ~ >>&! file ~ if file does not exist • Pipe ls -l | more ls -l > temp more < temp rm temp cmd1 |& cmd2

  9. Job Control ^Z : stop a running process jobs : display all the background and suspended jobs fg : bg : jobid stop : kill : kill -9 ps kill -9 jobid % jobnumber % name-prefix % + % - [1] stopped vi ... [2] - stopped mail... [3] + running lisp

  10. Job Control %cmd & fg running bg running fg bg bg stopped ^Z stop ^C or complete Kill or complete kill exit %cmd

  11. Input Process • History Substitutions • Alias Substitutions • Variable Substitutions • Command Substitution • File name expansion

  12. Input Process • History Substitution set history = n (length of history list) a event = a command line (whether successful or not) %history -r n (display the history list with sequence number) ! ^xx ^yy !n !* !-n !$ !! !^ !prefix !:n !?string event:s/xx/yy 1. ls -l !-2 = cd 7 cat file1 file2 file3 2. pwd !c = cd :0 :1 :2 :3 3. cd !?s = ls ^ $ 4. Ls : * !! = ls : !7 lpr !7^ !1 = ls -l more !7 : 2-3 lpr !^

  13. Input Process • General form event [: word designator ] [: modifier …] • event event number relative position command prefix matching string • word designator $n, ^, $ , * , $i-j , $I- , $-j , $i* • modifier /usr/src/ucb/prog.c h head !$:h /usr/src/ucb t tail !$:t prog.c r root !$:r /usr/src/ucb/prog e extension !$:e .c p print only

  14. Input Process • Alias Substitution • alias name definition alias dir ls alias ls ‘ls -F’ alias alias name unalias name --- remove alias cd ‘cd \ !* ; pwd ‘ alias csmail ‘mail \!:1%\!:2@relay.cs.net’ cd dir => cd dir ; pwd cs mail user host => mail user% host@relay.cs.net

  15. Input Process • Variable Substitution set maildir = /usr/spool/mail cd $maildir set x = abc echo ${x}def (abcdef) set path = ($home/command /usr/local/bin ...) echo path[2] (2nd argument) • Command Substitution set dir = ‘pwd’ <= 1.execute the command set file = ‘ls’ 2. assign the output to the variable set name = ‘pwd’/test.c

  16. Input Process • File Name Expansion * ? […] , { , , …} ~ . .. • Quote mechanism % echo * % echo ‘*’ % echo \* % echo ‘pwd’ % echo “$home” \ $ * ` “ ‘ ‘ n n n n n n “ y y n y n ` y n n n n

More Related