C shell编程初步.pdf
《C shell编程初步.pdf》由会员分享,可在线阅读,更多相关《C shell编程初步.pdf(44页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、An Introduction to the C shellWilliam Joy(revised for 4.3BSD by Mark Seiden)Computer Science DivisionDepartment of Electrical Engineering and Computer ScienceUniversity of California,BerkeleyBerkeley,California 94720ABSTRACTCsh is a new command language interpreter forUNIX systems.It incorporatesgoo
2、d features of other shells and a history mechanism similar to the redo ofINTERLISP.While incorporating many features of other shells which make writing shell programs(shell scripts)easier,most of the features unique to csh are designed more for the interac-tiveUNIXuser.UNIXusers who have read a gene
3、ral introduction to the system will find a valuablebasic explanation of the shell here.Simple terminal interaction with csh is possible afterreading just the first section of this document.The second section describes the shellscapabilities which you can explore after you have begun to become acquai
4、nted with theshell.Later sections introduce features which are useful,but not necessary for all users ofthe shell.Additional information includes an appendix listing special characters of the shelland a glossary of terms and commands introduced in this manual.IntroductionA shell is a command languag
5、e interpreter.Csh is the name of one particular command interpreteronUNIX.The primary purpose of csh is to translate command lines typed at a terminal into system actions,such as invocation of other programs.Csh is a user program just like any you might write.Hopefully,cshwill be a very useful progr
6、am for you in interacting with theUNIXsystem.In addition to this document,you will want to refer to a copy of theUNIXUser Reference Manual.The csh documentation in section 1 of the manual provides a full description of all features of the shell andis the definitive reference for questions about the
7、shell.Many words in this document are shown in italics.These are important words;names of commands,and words which have special meaning in discussing the shell andUNIX.Many of the words are defined ina glossary at the end of this document.If you dont know what is meant by a word,you should look for
8、itin the glossary.AcknowledgementsNumerous people have provided good input about previous versions of csh and aided in its debug-ging and in the debugging of its documentation.I would especially like to thank Michael Ubell who madethe crucial observation that history commands could be done well over
9、 the word structure of input text,andimplemented a prototype history mechanism in an older version of the shell.Eric Allman has also provideda large number of useful comments on the shell,helping to unify those concepts which are present and toUNIXis a trademark of Bell Laboratories.USD:4-2 An Intro
10、duction to the C shellidentify and eliminate useless and marginally useful features.Mike OBrien suggested the pathname hash-ing mechanism which speeds command execution.Jim Kulp added the job control and directory stackprimitives and added their documentation to this introduction.An Introduction to
11、the C shellUSD:4-31.Terminal usage of the shell1.1.The basic notion of commandsA shell inUNIXacts mostly as a medium through which other programs are invoked.While it has aset of builtin functions which it performs directly,most commands cause execution of programs that are,infact,external to the sh
12、ell.The shell is thus distinguished from the command interpreters of other systemsboth by the fact that it is just a user program,and by the fact that it is used almost exclusively as a mecha-nism for invoking other programs.Commands in theUNIXsystem consist of a list of strings or words interpreted
13、 as a command namefollowed by arguments.Thus the commandmail billconsists of two words.The first word mail names the command to be executed,in this case the mail pro-gram which sends messages to other users.The shell uses the name of the command in attempting toexecute it for you.It will look in a n
14、umber of directories for a file with the name mail which is expected tocontain the mail program.The rest of the words of the command are given as arguments to the command itself when it isexecuted.In this case we specified also the argument bill which is interpreted by the mail program to bethe name
15、 of a user to whom mail is to be sent.In normal terminal usage we might use the mail commandas follows.%mail billI hav e a question about the csh documentation.My document seems to be missing page 5.Does a page five exist?BillEOT%Here we typed a message to send to bill and ended this message with a
16、D which sent an end-of-fileto the mail program.(Here and throughout this document,the notation x is to be read control-x andrepresents the striking of the x key while the control key is held down.)The mail program then echoed thecharacters EOT and transmitted our message.The characters%were printed
17、before and after the mailcommand by the shell to indicate that input was needed.After typing the%prompt the shell was reading command input from our terminal.We typed acomplete command mail bill.The shell then executed the mail program with argument bill and wentdormant waiting for it to complete.Th
18、e mail program then read input from our terminal until we signalledan end-of-file via typing a D after which the shell noticed that mail had completed and signaled us that itwas ready to read from the terminal again by printing another%prompt.This is the essential pattern of all interaction withUNIX
19、through the shell.A complete command istyped at the terminal,the shell executes the command and when this execution completes,it prompts for anew command.If you run the editor for an hour,the shell will patiently wait for you to finish editing andobediently prompt you again whenever you finish editi
20、ng.An example of a useful command you can execute now is the tset command,which sets the defaulterase and kill characters on your terminal the erase character erases the last character you typed and thekill character erases the entire line you have entered so far.By default,the erase character is th
21、e delete key(equivalent to?)and the kill character is U.Some people prefer to make the erase character thebackspace key(equivalent to H).You can make this be true by typingtset ewhich tells the program tset to set the erase character to tsets default setting for this character(abackspace).USD:4-4 An
22、 Introduction to the C shell1.2.Flag argumentsA useful notion inUNIXis that of a flag argument.While many arguments to commands specify filenames or user names,some arguments rather specify an optional capability of the command which youwish to invoke.By convention,such arguments begin with the char
23、acter (hyphen).Thus the commandlswill produce a list of the files in the current working directory.The option s is the size option,andls scauses ls to also give,for each file the size of the file in blocks of 512 characters.The manual section foreach command in theUNIXreference manual gives the avai
24、lable options for each command.The ls com-mand has a large number of useful and interesting options.Most other commands have either no options oronly one or two options.It is hard to remember options of commands which are not used very frequently,so mostUNIXutilities perform only one or two function
25、s rather than having a large number of hard toremember options.1.3.Output to filesCommands that normally read input or write output on the terminal can also be executed with thisinput and/or output done to a file.Thus suppose we wish to save the current date in a file called now.The commanddatewill
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- shell编程初步 shell 编程 初步
限制150内