Professional Documents
Culture Documents
Devices, Terminals and CSH
Devices, Terminals and CSH
UNIX
Copyright B. Brown, 1988-2000. All rights reserved. March 2000.
Using the above example as a guide, write in the space provided below an alias for cd which prints the current directory whenever the cd command is used. _________________________________________________
uva.ulb.ac.be/cit_courseware/unix/unix16.htm
2/15/13
;ncobri st olbe s e ;apn t tm1 ped o ep ;rdrc sdu t tm1ee we ncobri st eiet tot o ep vn hn olbe s e
Built-In Commands
The C shell supports a number of built-in commands. alias assign new aliases or display current aliases. Type alias to list all current aliases. What is the current alias for cd? _________________________________________________ env displays the current environment. What is the current setting for the shell variable 'LOGNAME'? _________________________________________________ exit terminates the C shell (or a csh script). Do not type this command yet! Some systems use the command logout. history displays the contents of the history list. What was the second to last command typed? _________________________________________________ rehash causes the C shell to recompute a table of command locations. repeat causes the command to execute a number of times. Its format is repeat number command-list To echo the message 'help' on the console ten times, the command you would use is, _________________________________________________ setenv
uva.ulb.ac.be/cit_courseware/unix/unix16.htm 2/7
2/15/13
sets variables in the environment. How would you type to set the TERMinal variable to vt100 using the setenv command? _________________________________________________ source forces the C shell to read commands from a file. Its format is source file time causes the command to be timed. Its format is time command-list Use this command to find out how long a directory listing (with -la) takes. Enter the time taken in the space below. _________________________________________________ unalias removes aliases from the C shell. The command to remove the alias for cd is _________________________________________________ unset removes the C shell variable definition.
C Shell Statements
The following summary lists some of the C shell statements available in the C shell.
CniinlTss odtoa et
uva.ulb.ac.be/cit_courseware/unix/unix16.htm 3/7
2/15/13
= = ! = & & | |
Fl Tss ie et - fl ;ts wehrfl eit (aea Bun sel seapni frmr) e ie et hte ie xss sm s ore hl, e pedx o oe Flnm/xeso ieaeEtnin : r ;etatro o teflnm xrc ot f h ieae : e ;etatetnino flnm xrc xeso f ieae Fo Cnrl lw oto i (epeso )te f xrsin hn cmad omns .. . edf ni i (epeso )te f xrsin hn cmad omns .. . es i (epeso )te le f xrsin hn cmad omns .. . edf ni wie epeso ) hl( xrsin cmad omns ed n sic(wr ) wth od cs sr: ae t1 cmad omns bekw ras cs sr: ae tn cmad omns bekw ras dfut eal: cmad omns bekw ras edw ns frahi(ag) oec $rv cmad omns ed n bek ra; cniu; otne ei; xt lo: op cmad omns gt lo oo op
C Shell Scripts
uva.ulb.ac.be/cit_courseware/unix/unix16.htm 4/7
2/15/13
C Shell scripts must begin with the # symbol. Enter the following C shell script, naming it cscript1. Use vi editor to create the file.
#ccit,cpe ag[]t ag[]i ag[]de ntarayeit srp1 ois rv1 o rv2 f rv2 os o led xs i ($ag ! 2)te f #rv = hn eh "sg:cit sciedtie co uae ls1 rfl sfl" ei xt es le i (- $rv2 )te f e ag[] hn eh "ag[]arayeit.Fl ntcpe" co $rv2 led xss ie o oid es le c $rv1 $rv2 p ag[] ag[] eh "ag[]cpe t $rv2" co $rv1 oid o ag[] edf ni edf ni
Test the above script by typing the following commands. % csh cscript1 .profle cscript1 % csh cscript1 cscript1 csrcipt2 What was the message printed when the first command was typed? _________________________________________________ What was the message printed when the second command was typed? _________________________________________________
Handling Interrupts
The following example shows how to catch interrupts in a C shell script file.
#ccit cthn itrut srp3 acig nerps oircthn nt acit #cet vral iadeut t 1 rae aibe n qae o sti1 e = #mk atmoayfl ae eprr ie c srp3> tm$ p cit ! ep$ #etranvredn wielo ne ee nig hl op wie(i= 1) hl = :d ntigbtwi fra itrut o ohn u at o n nerp ed n
uva.ulb.ac.be/cit_courseware/unix/unix16.htm 5/7
2/15/13
#hr i itruthnlr rmv tm fl,ei srp ee s nerp ade, eoe ep ie xt cit cthn: acit r tm$ m ep$ ei() xt1
Review 5: csh
What is the output of the following C shell script. set i='/mnt/foo.bar' echo $i $i:r $i:e _________________________________________________ What does the following command assign to the variable 'pd'. set pd=`pwd` _________________________________________________ What does the 'repeat' command do? _________________________________________________ How do you exit the C shell if the variable 'ignoreeof' has been set? _________________________________________________
To Finish
Exit the C shell. Attach copies of your shell scripts to this booklet. Remove all your work files created for these modules (except any files beginning with a dot, eg, .profile). Logout of the Unix system. Attach a front declaration sheet and place this assignment in the assignment box.
uva.ulb.ac.be/cit_courseware/unix/unix16.htm
6/7
2/15/13
Flnm mtcaatr ieae eahrces / sprtscmoet o aflnmspt eaae opnns f ieae ah . sprtsro prso aflnm fo etnin eaae ot at f ieae rm xesos ? epnincaatrmthn aysnl caatr xaso hrce acig n ige hrce * epnincaatrmthn aysqec o caatr xaso hrce acig n eune f hrces [ ] epninsqec mthn aysnl caatrfo asto caatr xaso eune acig n ige hrce rm e f hrces ~ ue a tebgnigo aflnm t idct hm drcois sd t h einn f ieae o niae oe ietre { } ue t seiygop o agmnswt cmo prs sd o pcf rus f ruet ih omn at
Qoainmtcaatr utto eahrces \ peet mt-enn o tefloigsnl caatr rvns eamaig f h olwn ige hrce ' peet mt-enn o agopo caatr rvns eamaig f ru f hrces " lk ' btalw vral adcmadepeso ie , u los aibe n omn xrsin
Iptotu mtcaatr nu/upt eahrces < idctsrdrce ipt niae eietd nu > idctsrdrce otu niae eietd upt
Epninsbttto mtcaatr xaso/usiuin eahrces $ idctsvral sbttto niae aibe usiuin ! idctshsoysbttto niae itr usiuin : peee sbttto mdfes rcds usiuin oiir ^ ue i seilfrso hsoysbttto sd n pca om f itr usiuin ` idctscmadsbttto niae omn usiuin
Ohrmtcaatr te eahrces # bgn srthflnms idctsCselcmet eis cac ieae; niae hl omns peie oto (lg agmnst cmad rfxs pin fa) ruet o omns
Fl Tss ie et e fl eit ie xss d drcoy ietr f panfl li ie o onrhp wesi r ra acs ed ces w wieacs rt ces x eeueacs xct ces z zr lnt sz eo egh ie
uva.ulb.ac.be/cit_courseware/unix/unix16.htm
7/7