⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e2

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
字号:
.SHWriting text out as a file \- the Write command ``w''.PPIt's likely that you'll want to save your text for later use.To write out the contents of the buffer onto a file,use the.ulwritecommand.P1w.P2followed by the filename you want to write on.This will copy the buffer's contentsonto the specified file(destroying any previous information on the file).To savethe text on a file named.UL junk ,for example, type.P1w junk.P2Leave a space between.UL wand the file name..ulEdwill respond by printingthe number of characters it wrote out.In this case,.uledwould respond with.P168.P2(Remember that blanks and the return character at the end of eachline are included in the character count.)Writing a file just makes a copy of the text \- thebuffer's contents are not disturbed, so you can go on addinglines to it.This is an important point..ulEdat all times works on a copyof a file, not the file itself.No change in the contentsof a file takes place until you give a.UL wcommand.(Writing out the text onto a file from time to time as it is beingcreated is a good idea, since if the system crashes or if you make some horrible mistake, you will loseall the text in the buffer but any text that was written ontoa file is relatively safe.).SHLeaving ed \- the Quit command ``q''.PPTo terminate a session with.IT ed ,save the text you're working onby writing it onto a file using the.UL wcommand,and then type the command.P1q.P2whichstands for.IT quit .The system will respond withthe prompt character.UL $ "" (or.UL % ).Atthis point your buffer vanishes, with all its text,which is why you want to write it out before quitting.\(dg.FS\(dg Actually,.IT edwill print .UL ?if you try to quit without writing.At that point, write if you want;if not, another.UL qwill get you out regardless..FE.SHExercise 1:.PPEnter.uledandcreate some text using.P1a\&. . . text . . .\&\fB.\fR.P2Write it out using.UL w .Then leave.uledwith the.UL qcommand, and print the file,to see that everything worked.(To print a file, say.P1pr filename.P2or.P1cat filename.P2in response tothe prompt character.Try both.).SHReading text from a file \- the Edit command ``e''.PPA common way to get text into the buffer is to read itfrom a file in the file system.This is what you do to edit textthat you saved with the .UL wcommand in a previous session.The.uleditcommand.UL efetches the entire contents of a file into the buffer.So if you had saved the three lines``Now is the time'', etc.,with a.UL wcommand in an earlier session,the .uledcommand.P1e junk.P2would fetch the entire contents of the file.UL junkinto the buffer, and respond.P168.P2which is the number of characters in.UL junk ..ulIf anything was already in the buffer, it is deleted first..PPIf you use the.UL ecommand to read a file into the buffer,then you need not use a file name after a subsequent.UL wcommand;.uledremembers the last file name used in an.UL ecommand,and.UL wwill write on this file.Thus a good way to operate is.P1ede file[editing session]wq.P2This way, you can simply say.UL wfrom time to time,and be secure in the knowledge thatif you got the file name right at the beginning,you are writing into the proper file each time..PPYou can find out at any time what file name.uledis remembering by typing the .ulfilecommand.UL f .In this example,if you typed.P1f.P2.uledwould reply.P1junk.P2.SHReading text from a file \- the Read command ``r''.PPSometimes you want to read a file into the bufferwithout destroying anything that is already there.This is done by the.ulreadcommand.UL r .The command.P1r junk.P2will read the file.UL junkinto the buffer;it adds itto the end of whatever is already in the buffer.So if you do a read afteran edit:.P1e junkr junk.P2the buffer will contain.ultwocopies of the text (six lines)..P1Now is the timefor all good mento come to the aid of their party.Now is the timefor all good mento come to the aid of their party..P2Like the.UL wand.UL ecommands,.UL rprintsthenumber of characters read in, after the reading operation is complete..PPGenerally speaking,.UL ris much less used than.UL e ..SHExercise 2:.PPExperiment with the.UL ecommand \-try reading and printing various files.You may get an error.UL ?name ,where.UL nameis the name of a file;this means that the file doesn't exist,typically because you spelled the file name wrong,or perhaps that you are not allowed to read or write it.Try alternately reading and appending to see that they worksimilarly.Verify that.P1ed filename.P2is exactly equivalent to.P1ede filename.P2What does.P1f filename.P2do?.SHPrinting the contents of the buffer \- the Print command ``p''.PPTo.ulprintor list the contents of the buffer (or partsof it) on the terminal, use the print command.P1p.P2The way this is done is as follows.Specify the lines whereyou want printing to begin and where you want it to end,separated by a comma, andfollowed by the letter.UL p .Thus to print the first two lines of the buffer, forexample, (that is, lines 1 through 2) say.P11,2p	(starting line=1, ending line=2 p).P2.ulEdwill respond with.P1Now is the timefor all good men.P2.PPSuppose you want to print.ulallthe lines in the buffer.You could use.UL 1,3pas above if you knew there were exactly3 lines in the buffer.But in general, you don'tknow how many there are, so what do you use for the endingline number?.ulEdprovides a shorthand symbol for ``line number oflast line in buffer'' \- the dollar sign.UL $ .Use it thisway:.P11,$p.P2This will print.ulallthe lines in the buffer (line 1 to last line.)If you want to stop the printing before it is finished,push the.UC DELor Delete key;.uledwill type.P1?.P2and wait for the next command..PPTo print the.ullastline of the buffer, you could use.P1$,$p.P2but.uledlets you abbreviate this to.P1$p.P2You can print any single line by typing the linenumber followed by a.UL p .Thus.P11p.P2produces the response.P1Now is the time.P2which is the first line of the buffer..PPIn fact,.uledlets you abbreviate even further:you can print any single line by typing.uljustthe line number \- no need to type the letter.UL p .So if you say.P1$.P2.uledwill print the last line of the buffer..PPYou can also use.UL $in combinations like.P1$\-1,$p.P2which prints the last two lines of the buffer.This helps when you want to see how far you got in typing..SHExercise 3:.PPAs before, create some text using the.UL acommand andexperiment with the.UL pcommand.You will find, for example,that you can't print line 0 or a line beyondthe end of the buffer, and that attemptsto print a buffer in reverse order by saying.P13,1p.P2don't work.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -