new copyright; att/bsd/shared
[unix-history] / usr / src / share / doc / usd / 01.begin / u2
CommitLineData
ff262511
KB
1.\" %sccs.include.proprietary.roff%
2.\"
3.\" @(#)u2 6.2 (Berkeley) %G%
fc2a7a49
KD
4.\"
5.SH
6II. DAY-TO-DAY USE
7.SH
8Creating Files \(em The Editor
9.PP
10If you have to type a paper or a letter or a program,
11how do you get the information stored in the machine?
12Most of these tasks are done with
13the
14.UC UNIX
15``text editor''
16.UL ed .
17Since
18.UL ed
19is thoroughly documented in
20.UL ed (1)
21and explained in
22.ul
23A Tutorial Introduction to the UNIX Text Editor,
24we won't spend any time here describing how to use it.
25All we want it for right now is to make some
26.ul
27files.
28(A file is just a collection of information stored in the machine,
29a simplistic but adequate definition.)
30.PP
31To create a file
32called
33.UL junk
34with some text in it, do the following:
35.P1
36.ta .65i
37ed junk \fR(invokes the text editor)\f3
38a \fR(command to ``ed'', to add text)\f3
39.ft I
40now type in
41whatever text you want ...
42.ft 3
43\&. \fR(signals the end of adding text)\f3
44.P2
45The ``\f3.\fR'' that signals the end of adding text must be
46at the beginning of a line by itself.
47Don't forget it,
48for until it is typed,
49no other
50.UL ed
51commands will be recognized \(em
52everything you type will be treated as text to be added.
53.PP
54At this point you can do various editing operations
55on the text you typed in, such as correcting spelling mistakes,
56rearranging paragraphs and the like.
57Finally, you must write the information you have typed
58into a file with the editor command
59.UL w :
60.P1
61w
62.P2
63.UL ed
64will respond with the number of characters it wrote
65into the file
66.UL junk .
67.PP
68Until the
69.UL w
70command,
71nothing is stored permanently,
72so if you hang up and go home
73the information is lost.\(dg
74.FS
75\(dg This is not strictly true \(em
76if you hang up while editing, the data you were
77working on is saved in a file called
78.UL ed.hup ,
79which you can continue with at your next session.
80.FE
81But after
82.UL w
83the information is there permanently;
84you can re-access it any time by typing
85.P1
86ed junk
87.P2
88Type a
89.UL q
90command
91to quit the editor.
92(If you try to quit without writing,
93.UL ed
94will print a
95.UL ?
96to remind you.
97A second
98.UL q
99gets you out regardless.)
100.PP
101Now create a second file called
102.UL temp
103in the same manner.
104You should now have two files,
105.UL junk
106and
107.UL temp .
108.SH
109What files are out there?
110.PP
111The
112.UL ls
113(for ``list'') command lists the names
114(not contents)
115of any of the files that
116.UC UNIX
117knows about.
118If you type
119.P1
120ls
121.P2
122the response will be
123.P1
124junk
125temp
126.P2
127which are indeed the two files just created.
128The names are sorted into alphabetical order automatically,
129but other variations are possible.
130For example,
131the command
132.P1
133ls -t
134.P2
135causes the files to be listed in the order in which they were last changed,
136most recent first.
137The
138.UL \-l
139option gives a ``long'' listing:
140.P1
141ls -l
142.P2
143will produce something like
144.P1
145-rw-rw-rw- 1 bwk 41 Jul 22 2:56 junk
146-rw-rw-rw- 1 bwk 78 Jul 22 2:57 temp
147.P2
148The date and time are of the last change to the file.
149The 41 and 78 are the number of characters
150(which should agree with the numbers you got from
151.UL ed ).
152.UL bwk
153is the owner of the file, that is, the person
154who created it.
155The
156.UL \-rw\-rw\-rw\-
157tells who has permission to read and write the file,
158in this case everyone.
159.PP
160Options can be combined:
161.UL ls\ \-lt
162gives the same thing as
163.UL ls\ \-l ,
164but sorted into time order.
165You can also name the files you're interested in,
166and
167.UL ls
168will list the information about them only.
169More details can be found in
170.UL ls (1).
171.PP
172The use of optional arguments that begin with a minus sign,
173like
174.UL \-t
175and
176.UL \-lt ,
177is a common convention for
178.UC UNIX
179programs.
180In general, if a program accepts such optional arguments,
181they precede any filename arguments.
182It is also vital that you separate the various arguments with spaces:
183.UL ls\-l
184is not the same as
185.UL ls\ \ \-l .
186.SH
187Printing Files
188.PP
189Now that you've got a file of text,
190how do you print it so people can look at it?
191There are a host of programs that do that,
192probably more than are needed.
193.PP
194One simple thing is to use the editor,
195since printing is often done just before making changes anyway.
196You can say
197.P1
198ed junk
1991,$p
200.P2
201.UL ed
202will reply with the count of the characters in
203.UL junk
204and then print all the lines in the file.
205After you learn how to use the editor,
206you can be selective about the parts you print.
207.PP
208There are times when it's not feasible to use the editor for printing.
209For example, there is a limit on how big a file
210.UL ed
211can handle
212(several thousand lines).
213Secondly,
214it
215will only print one file at a time,
216and sometimes you want to print several, one after another.
217So here are a couple of alternatives.
218.PP
219First is
220.UL cat ,
221the simplest of all the printing programs.
222.UL cat
223simply prints on the terminal the contents of all the files
224named in a list.
225Thus
226.P1
227cat junk
228.P2
229prints one file, and
230.P1
231cat junk temp
232.P2
233prints two.
234The files are simply concatenated (hence the name
235.UL cat '') ``
236onto the terminal.
237.PP
238.UL pr
239produces formatted printouts of files.
240As with
241.UL cat ,
242.UL pr
243prints all the files named in a list.
244The difference is that it produces
245headings with date, time, page number and file name
246at the top of each page,
247and
248extra lines to skip over the fold in the paper.
249Thus,
250.P1
251pr junk temp
252.P2
253will print
254.UL junk
255neatly,
256then skip to the top of a new page and print
257.UL temp
258neatly.
259.PP
260.UL pr
261can also produce multi-column output:
262.P1
263pr -3 junk
264.P2
265prints
266.UL junk
267in 3-column format.
268You can use any reasonable number in place of ``3''
269and
270.UL pr
271will do its best.
272.UL pr
273has other capabilities as well;
274see
275.UL pr (1).
276.PP
277It should be noted that
278.UL pr
279is
280.ul
281not
282a formatting program in the sense of shuffling lines around
283and justifying margins.
284The true formatters are
285.UL nroff
286and
287.UL troff ,
288which we will get to in the section on document preparation.
289.PP
290There are also programs that print files
291on a high-speed printer.
292Look in your manual under
293.UL opr
294and
295.UL lpr .
296Which to use depends on
297what equipment is attached to your machine.
298.SH
299Shuffling Files About
300.PP
301Now that you have some files in the file system
302and some experience in printing them,
303you can try bigger things.
304For example,
305you can move a file from one place to another
306(which amounts to giving it a new name),
307like this:
308.P1
309mv junk precious
310.P2
311This means that what used to be ``junk'' is now ``precious''.
312If you do an
313.UL ls
314command now,
315you will get
316.P1
317precious
318temp
319.P2
320Beware that if you move a file to another one
321that already exists,
322the already existing contents are lost forever.
323.PP
324If you want
325to make a
326.ul
327copy
328of a file (that is, to have two versions of something),
329you can use the
330.UL cp
331command:
332.P1
333cp precious temp1
334.P2
335makes a duplicate copy of
336.UL precious
337in
338.UL temp1 .
339.PP
340Finally, when you get tired of creating and moving
341files,
342there is a command to remove files from the file system,
343called
344.UL rm .
345.P1
346rm temp temp1
347.P2
348will remove both of the files named.
349.PP
350You will get a warning message if one of the named files wasn't there,
351but otherwise
352.UL rm ,
353like most
354.UC UNIX
355commands,
356does its work silently.
357There is no prompting or chatter,
358and error messages are occasionally curt.
359This terseness is sometimes disconcerting
360to new\%comers,
361but experienced users find it desirable.
362.SH
363What's in a Filename
364.PP
365So far we have used filenames without ever saying what's
366a legal name,
367so it's time for a couple of rules.
368First, filenames are limited to 14 characters,
7f5db720
KD
369which is enough to be descriptive.\(dg
370.FS
371\(dg In 4.2 BSD the limit was extended to 255 characters.
372.FE
fc2a7a49
KD
373Second, although you can use almost any character
374in a filename,
375common sense says you should stick to ones that are visible,
376and that you should probably avoid characters that might be used
377with other meanings.
378We have already seen, for example,
379that in the
380.UL ls
381command,
382.UL ls\ \-t
383means to list in time order.
384So if you had a file whose name
385was
386.UL \-t ,
387you would have a tough time listing it by name.
388Besides the minus sign, there are other characters which
389have special meaning.
390To avoid pitfalls,
391you would do well to
392use only letters, numbers and the period
393until you're familiar with the situation.
394.PP
395On to some more positive suggestions.
396Suppose you're typing a large document
397like a book.
398Logically this divides into many small pieces,
399like chapters and perhaps sections.
400Physically it must be divided too,
401for
402.UL ed
403will not handle really big files.
404Thus you should type the document as a number of files.
405You might have a separate file for each chapter,
406called
407.P1
408chap1
409chap2
410.ft R
411etc...
412.P2
413Or, if each chapter were broken into several files, you might have
414.P1
415chap1.1
416chap1.2
417chap1.3
418\&...
419chap2.1
420chap2.2
421\&...
422.P2
423You can now tell at a glance where a particular file fits into the whole.
424.PP
425There are advantages to a systematic naming convention which are not obvious
426to the novice
427.UC UNIX
428user.
429What if you wanted to print the whole book?
430You could say
431.P1
432pr chap1.1 chap1.2 chap1.3 ......
433.P2
434but you would get tired pretty fast, and would probably even make mistakes.
435Fortunately, there is a shortcut.
436You can say
437.P1
438pr chap*
439.P2
440The
441.UL *
442means ``anything at all,''
443so this translates into ``print all files
444whose names begin with
445.UL chap '',
446listed in alphabetical order.
447.PP
448This shorthand notation
449is not a property of the
450.UL pr
451command, by the way.
452It is system-wide, a service of the program
453that interprets commands
454(the ``shell,''
455.UL sh (1)).
456Using that fact, you can see how to list the names of the files in the book:
457.P1
458ls chap*
459.P2
460produces
461.P1
462chap1.1
463chap1.2
464chap1.3
465\&...
466.P2
467The
468.UL *
469is not limited to the last position in a filename \(em
470it can be anywhere
471and can occur several times.
472Thus
473.P1
474rm *junk* *temp*
475.P2
476removes all files that contain
477.UL junk
478or
479.UL temp
480as any part of their name.
481As a special case,
482.UL *
483by itself matches every filename,
484so
485.P1
486pr *
487.P2
488prints all your files
489(alphabetical order),
490and
491.P1
492rm *
493.P2
494removes
495.ul
496all files.
497(You had better be
498.IT very
499sure that's what you wanted to say!)
500.PP
501The
502.UL *
503is not
504the only pattern-matching feature available.
505Suppose you want to print only chapters 1 through 4 and 9.
506Then you can say
507.P1
508pr chap[12349]*
509.P2
510The
511.UL [...]
512means to match any of the characters inside the brackets.
513A range of consecutive letters or digits can be abbreviated,
514so you can also do this
515with
516.P1
517pr chap[1-49]*
518.P2
519Letters can also be used within brackets:
520.UL [a\-z]
521matches any character in the range
522.UL a
523through
524.UL z .
525.PP
526The
527.UL ?
528pattern matches any single character,
529so
530.P1
531ls ?
532.P2
533lists all files which have single-character names,
534and
535.P1
536ls -l chap?.1
537.P2
538lists information about the first file of each chapter
539.UL chap1.1 \&, (
540.UL chap2.1 ,
541etc.).
542.PP
543Of these niceties,
544.UL *
545is certainly the most useful,
546and you should get used to it.
547The others are frills, but worth knowing.
548.PP
549If you should ever have to turn off the special meaning
550of
551.UL * ,
552.UL ? ,
553etc.,
554enclose the entire argument in single quotes,
555as in
556.P1
557ls \(fm?\(fm
558.P2
559We'll see some more examples of this shortly.
560.SH
561What's in a Filename, Continued
562.PP
563When you first made that file called
564.UL junk ,
565how did
566the system
567know that there wasn't another
568.UL junk
569somewhere else,
570especially since the person in the next office is also
571reading this tutorial?
572The answer is that generally each user
573has a private
574.IT directory ,
575which contains only the files that belong to him.
576When you log in, you are ``in'' your directory.
577Unless you take special action,
578when you create a new file,
579it is made in the directory that you are currently in;
580this is most often your own directory,
581and thus the file is unrelated to any other file of the same name
582that might exist in someone else's directory.
583.PP
584The set of all files
585is organized into a (usually big) tree,
586with your files located several branches into the tree.
587It is possible for you to ``walk'' around this tree,
588and to find any file in the system, by starting at the root
589of the tree and walking along the proper set of branches.
590Conversely, you can start where you are and walk toward the root.
591.PP
592Let's try the latter first.
593The basic tools is the command
594.UL pwd
595(``print working directory''),
596which prints the name of the directory you are currently in.
597.PP
598Although the details will vary according to the system you are on,
599if you give the
600command
601.UL pwd ,
602it will print something like
603.P1
604/usr/your\(hyname
605.P2
606This says that you are currently in the directory
607.UL your-name ,
608which is in turn in the directory
609.UL /usr ,
610which is in turn in the root directory
611called by convention just
612.UL / .
613(Even if it's not called
614.UL /usr
615on your system,
616you will get something analogous.
7f5db720 617Make the corresponding mental adjustment and read on.)
fc2a7a49
KD
618.PP
619If you now type
620.P1
621ls /usr/your\(hyname
622.P2
623you should get exactly the same list of file names
624as you get from a plain
625.UL ls :
626with no arguments,
627.UL ls
628lists the contents of the current directory;
629given the name of a directory,
630it lists the contents of that directory.
631.PP
632Next, try
633.P1
634ls /usr
635.P2
636This should print a long series of names,
637among which is your own login name
638.UL your-name .
639On many systems,
640.UL usr
641is a directory that contains the directories
642of all the normal users of the system,
643like you.
644.PP
645The next step is to try
646.P1
647ls /
648.P2
649You should get a response something like this
650(although again the details may be different):
651.P1
652bin
653dev
654etc
655lib
656tmp
657usr
658.P2
659This is a collection of the basic directories of files
660that
661the system
662knows about;
663we are at the root of the tree.
664.PP
665Now try
666.P1
667cat /usr/your\(hyname/junk
668.P2
669(if
670.UL junk
671is still around in your directory).
672The name
673.P1
674/usr/your\(hyname/junk
675.P2
676is called the
677.UL pathname
678of the file that
679you normally think of as ``junk''.
680``Pathname'' has an obvious meaning:
681it represents the full name of the path you have to follow from the root
682through the tree of directories to get to a particular file.
683It is a universal rule in
684the
685.UC UNIX
686system
687that anywhere you can use an ordinary filename,
688you can use a pathname.
689.PP
690Here is a picture which may make this clearer:
691.P1 1
692.ft R
693.if t .vs 9p
694.if t .tr /\(sl
695.if t .tr ||
696.ce 100
697(root)
698/ | \e
699/ | \e
700/ | \e
701 bin etc usr dev tmp
702/ | \e / | \e / | \e / | \e / | \e
703/ | \e
704/ | \e
705adam eve mary
706/ / \e \e
707 / \e junk
708junk temp
709.ce 0
710.br
711.tr //
712.P2
713.LP
714Notice that Mary's
715.UL junk
716is unrelated to Eve's.
717.PP
718This isn't too exciting if all the files of interest are in your own
719directory, but if you work with someone else
720or on several projects concurrently,
721it becomes handy indeed.
722For example, your friends can print your book by saying
723.P1
724pr /usr/your\(hyname/chap*
725.P2
726Similarly, you can find out what files your neighbor has
727by saying
728.P1
729ls /usr/neighbor\(hyname
730.P2
731or make your own copy of one of his files by
732.P1
733cp /usr/your\(hyneighbor/his\(hyfile yourfile
734.P2
735.PP
736If your neighbor doesn't want you poking around in his files,
737or vice versa,
738privacy can be arranged.
739Each file and directory has read-write-execute permissions for the owner,
740a group, and everyone else,
741which can be set
742to control access.
743See
744.UL ls (1)
745and
746.UL chmod (1)
747for details.
748As a matter of observed fact,
749most users most of the time find openness of more
750benefit than privacy.
751.PP
752As a final experiment with pathnames, try
753.P1
754ls /bin /usr/bin
755.P2
756Do some of the names look familiar?
757When you run a program, by typing its name after the prompt character,
758the system simply looks for a file of that name.
759It normally looks first in your directory
760(where it typically doesn't find it),
761then in
762.UL /bin
763and finally in
764.UL /usr/bin .
765There is nothing magic about commands like
766.UL cat
767or
768.UL ls ,
769except that they have been collected into a couple of places to be easy to find and administer.
770.PP
771What if you work regularly with someone else on common information
772in his directory?
773You could just log in as your friend each time you want to,
774but you can also say
775``I want to work on his files instead of my own''.
776This is done by changing the directory that you are
777currently in:
778.P1
779cd /usr/your\(hyfriend
780.P2
781(On some systems,
782.UL cd
783is spelled
784.UL chdir .)
785Now when you use a filename in something like
786.UL cat
787or
788.UL pr ,
789it refers to the file in your friend's directory.
790Changing directories doesn't affect any permissions associated
791with a file \(em
792if you couldn't access a file from your own directory,
793changing to another directory won't alter that fact.
794Of course,
795if you forget what directory you're in, type
796.P1
797pwd
798.P2
799to find out.
800.PP
801It is usually convenient to arrange your own files
802so that all the files related to one thing are in a directory separate
803from other projects.
804For example, when you write your book, you might want to keep all the text
805in a directory called
806.UL book .
807So make one with
808.P1
809mkdir book
810.P2
811then go to it with
812.P1
813cd book
814.P2
815then start typing chapters.
816The book is now found in (presumably)
817.P1
818/usr/your\(hyname/book
819.P2
820To remove the directory
821.UL book ,
822type
823.P1
824rm book/*
825rmdir book
826.P2
827The first command removes all files from the directory;
828the second
829removes the empty directory.
830.PP
831You can go up one level in the tree of files
832by saying
833.P1
834cd ..
835.P2
836.UL .. '' ``
837is the name of the parent of whatever directory you are currently in.
838For completeness,
839.UL . '' ``
840is an alternate name
841for the directory you are in.
842.SH
843Using Files instead of the Terminal
844.PP
845Most of the commands we have seen so far produce output
846on the terminal;
847some, like the editor, also take their input from the terminal.
848It is universal in
849.UC UNIX
850systems
851that the terminal can be replaced by a file
852for either or both of input and output.
853As one example,
854.P1
855ls
856.P2
857makes a list of files on your terminal.
858But if you say
859.P1
860ls >filelist
861.P2
862a list of your files will be placed in the file
863.UL filelist
864(which
865will be created if it doesn't already exist,
866or overwritten if it does).
867The symbol
868.UL >
869means ``put the output on the following file,
870rather than on the terminal.''
871Nothing is produced on the terminal.
872As another example, you could combine
873several files into one by capturing the output of
874.UL cat
875in a file:
876.P1
877cat f1 f2 f3 >temp
878.P2
879.PP
880The symbol
881.UL >>
882operates very much like
883.UL >
884does,
885except that it means
886``add to the end of.''
887That is,
888.P1
889cat f1 f2 f3 >>temp
890.P2
891means to concatenate
892.UL f1 ,
893.UL f2
894and
895.UL f3
896to the end of whatever is already in
897.UL temp ,
898instead of overwriting the existing contents.
899As with
900.UL > ,
901if
902.UL temp
903doesn't exist, it will be created for you.
904.PP
905In a similar way, the symbol
906.UL <
907means to take the input
908for a program from the following file,
909instead of from the terminal.
910Thus, you could make up a script of commonly used editing commands
911and put them into a file called
912.UL script .
913Then you can run the script on a file by saying
914.P1
915ed file <script
916.P2
917As another example, you can use
918.UL ed
919to prepare a letter in file
920.UL let ,
921then send it to several people with
922.P1
923mail adam eve mary joe <let
924.P2
925.SH
926Pipes
927.PP
928One of the novel contributions of
929the
930.UC UNIX
931system
932is the idea of a
933.ul
934pipe.
935A pipe is simply a way to connect the output of one program
936to the input of another program,
937so the two run as a sequence of processes \(em
938a pipeline.
939.PP
940For example,
941.P1
942pr f g h
943.P2
944will print the files
945.UL f ,
946.UL g ,
947and
948.UL h ,
949beginning each on a new page.
950Suppose you want
951them run together instead.
952You could say
953.P1
954cat f g h >temp
955pr <temp
956rm temp
957.P2
958but this is more work than necessary.
959Clearly what we want is to take the output of
960.UL cat
961and
962connect it to the input of
963.UL pr .
964So let us use a pipe:
965.P1
966cat f g h | pr
967.P2
968The vertical bar
969.UL |
970means to
971take the output from
972.UL cat ,
973which would normally have gone to the terminal,
974and put it into
975.UL pr
976to be neatly formatted.
977.PP
978There are many other examples of pipes.
979For example,
980.P1
981ls | pr -3
982.P2
983prints a list of your files in three columns.
984The program
985.UL wc
986counts the number of lines, words and characters in
987its input, and as we saw earlier,
988.UL who
989prints a list of currently-logged on people,
990one per line.
991Thus
992.P1
993who | wc
994.P2
995tells how many people are logged on.
996And of course
997.P1
998ls | wc
999.P2
1000counts your files.
1001.PP
1002Any program
1003that reads from the terminal
1004can read from a pipe instead;
1005any program that writes on the terminal can drive
1006a pipe.
1007You can have as many elements in a pipeline as you wish.
1008.PP
1009Many
1010.UC UNIX
1011programs are written so that they will take their input from one or more files
1012if file arguments are given;
1013if no arguments are given they will read from the terminal,
1014and thus can be used in pipelines.
1015.UL pr
1016is one example:
1017.P1
1018pr -3 a b c
1019.P2
1020prints files
1021.UL a ,
1022.UL b
1023and
1024.UL c
1025in order in three columns.
1026But in
1027.P1
1028cat a b c | pr -3
1029.P2
1030.UL pr
1031prints the information coming down the pipeline,
1032still in
1033three columns.
1034.SH
1035The Shell
1036.PP
1037We have already mentioned once or twice the mysterious
1038``shell,''
1039which is in fact
7f5db720
KD
1040.UL sh (1).\(dg
1041.FS
1042\(dg On Berkeley Unix systems, the usual shell for interactive use is the c shell,
1043.UL csh(1).
1044.FE
fc2a7a49
KD
1045The shell is the program that interprets what you type as
1046commands and arguments.
1047It also looks after translating
1048.UL * ,
1049etc.,
1050into lists of filenames,
1051and
1052.UL < ,
1053.UL > ,
1054and
1055.UL |
1056into changes of input and output streams.
1057.PP
1058The shell has other capabilities too.
1059For example, you can run two programs with one command line
1060by separating the commands with a semicolon;
1061the shell recognizes the semicolon and
1062breaks the line into two commands.
1063Thus
1064.P1
1065date; who
1066.P2
1067does both commands before returning with a prompt character.
1068.PP
1069You can also have more than one program running
1070.ul
1071simultaneously
1072if you wish.
1073For example, if you are doing something time-consuming,
1074like the editor script
1075of an earlier section,
1076and you don't want to wait around for the results before starting something else,
1077you can say
1078.P1
1079ed file <script &
1080.P2
1081The ampersand at the end of a command line
1082says ``start this command running,
1083then take further commands from the terminal immediately,''
1084that is,
1085don't wait for it to complete.
1086Thus the script will begin,
1087but you can do something else at the same time.
1088Of course, to keep the output from interfering
1089with what you're doing on the terminal,
1090it would be better to say
1091.P1
1092ed file <script >script.out &
1093.P2
1094which saves the output lines in a file
1095called
1096.UL script.out .
1097.PP
1098When you initiate a command with
1099.UL & ,
1100the system
1101replies with a number
1102called the process number,
1103which identifies the command in case you later want
1104to stop it.
1105If you do, you can say
1106.P1
1107kill process\(hynumber
1108.P2
1109If you forget the process number,
1110the command
1111.UL ps
1112will tell you about everything you have running.
1113(If you are desperate,
1114.UL kill\ 0
1115will kill all your processes.)
1116And if you're curious about other people,
1117.UL ps\ a
1118will tell you about
1119.ul
1120all
1121programs that are currently running.
1122.PP
1123You can say
1124.P1 1
1125(command\(hy1; command\(hy2; command\(hy3) &
1126.P2
1127to start three commands in the background,
1128or you can start a background pipeline with
1129.P1
1130command\(hy1 | command\(hy2 &
1131.P2
1132.PP
1133Just as you can tell the editor
1134or some similar program to take its input
1135from a file instead of from the terminal,
1136you can tell the shell to read a file
1137to get commands.
1138(Why not? The shell, after all, is just a program,
1139albeit a clever one.)
1140For instance, suppose you want to set tabs on
1141your terminal, and find out the date
1142and who's on the system every time you log in.
1143Then you can put the three necessary commands
1144.UL tabs , (
1145.UL date ,
1146.UL who )
1147into a file, let's call it
1148.UL startup ,
1149and then run it with
1150.P1
1151sh startup
1152.P2
1153This says to run the shell with the file
1154.UL startup
1155as input.
1156The effect is as if you had typed
1157the contents of
1158.UL startup
1159on the terminal.
1160.PP
1161If this is to be a regular thing,
1162you can eliminate the
1163need to type
1164.UL sh :
1165simply type, once only, the command
1166.P1
1167chmod +x startup
1168.P2
1169and thereafter you need only say
1170.P1
1171startup
1172.P2
1173to run the sequence of commands.
1174The
1175.UL chmod (1)
1176command marks the file executable;
1177the shell recognizes this and runs it as a sequence of commands.
1178.PP
1179If you want
1180.UL startup
1181to run automatically every time you log in,
1182create a file in your login directory called
1183.UL .profile ,
1184and place in it the line
1185.UL startup .
1186When the shell first gains control when you log in,
1187it looks for the
1188.UL .profile
7f5db720
KD
1189file and does whatever commands it finds in it.\(dg
1190.FS
1191\(dg The c shell instead reads a file called
1192.UL .login
1193.
1194.FE
fc2a7a49
KD
1195We'll get back to the shell in the section
1196on programming.