X {neg moveto {2 index stringwidth pop sub exch div 0 32 4 -1 roll widthshow} repeat}
X {neg moveto {spacewidth sub 0.0 32 4 -1 roll widthshow} repeat}
X {counttomark 2 idiv {y moveto show} repeat}
X {neg setfunnytext}
] def
X
/setdecoding {/t decodingdefs 3 -1 roll get bind def} bind def
X
/w {neg moveto show} bind def
/m {neg dup /y exch def moveto} bind def
/done {/lastpage where {pop lastpage} if} def
X
/f {
X dup /font exch def findfont exch
X dup /ptsize exch def scaling div dup /size exch def scalefont setfont
X linewidth ptsize mul scaling 10 mul div setlinewidth
X /spacewidth ( ) stringwidth pop def
} bind def
X
/changefont {
X /fontheight exch def
X /fontslant exch def
X currentfont [
X 1 0
X fontheight ptsize div fontslant sin mul fontslant cos div
X fontheight ptsize div
X 0 0
X ] makefont setfont
} bind def
X
/sf {f} bind def
X
/cf {
X dup length 2 idiv
X /entries exch def
X /chtab exch def
X /newfont exch def
X
X findfont dup length 1 add dict
X /newdict exch def
X {1 index /FID ne {newdict 3 1 roll put} {pop pop} ifelse} forall
X
X newdict /Metrics entries dict put
X newdict /Metrics get
X begin
X chtab aload pop
X 1 1 entries {pop def} for
X newfont newdict definefont pop
X end
} bind def
X
%
% A few arrays used to adjust reference points and character widths in some
% of the printer resident fonts. If square roots are too high try changing
% the lines describing /radical and /radicalex to,
%
% /radical [0 -75 550 0]
% /radicalex [-50 -75 500 0]
%
% Move braceleftbt a bit - default PostScript character is off a bit.
%
X
/Sdefs [
X /bracketlefttp [201 500]
X /bracketleftbt [201 500]
X /bracketrighttp [-81 380]
X /bracketrightbt [-83 380]
X /braceleftbt [203 490]
X /bracketrightex [220 -125 500 0]
X /radical [0 0 550 0]
X /radicalex [-50 0 500 0]
X /parenleftex [-20 -170 0 0]
X /integral [100 -50 500 0]
X /infinity [10 -75 730 0]
] def
X
/S1defs [
X /underscore [0 80 500 0]
X /endash [7 90 650 0]
] def
%
% Tries to round clipping path dimensions, as stored in array pagebbox, so they
% match one of the known sizes in the papersizes array. Lower left coordinates
% are always set to 0.
%
X
/roundpagebbox {
X 7 dict begin
X /papersizes [8.5 inch 11 inch 14 inch 17 inch] def
X
X /mappapersize {
X /val exch def
X /slop .5 inch def
X /diff slop def
X /j 0 def
X 0 1 papersizes length 1 sub {
X /i exch def
X papersizes i get val sub abs
X dup diff le {/diff exch def /j i def} {pop} ifelse
X } for
X diff slop lt {papersizes j get} {val} ifelse
X } def
X
X pagebbox 0 0 put
X pagebbox 1 0 put
X pagebbox dup 2 get mappapersize 2 exch put
X pagebbox dup 3 get mappapersize 3 exch put
X end
} bind def
X
%%EndProlog
%%BeginSetup
mark
/linewidth 0.5 def
/xoffset 0 def
/yoffset 0 def
/#copies 1 store
/magnification 1 def
%%FormsPerPage: 1
/formsperpage 1 def
X
/landscape false def
/resolution 720 def
setup
2 setdecoding
%%EndSetup
%%Page: 1 1
/saveobj save def
mark
1 pagesetup
12 B f
(Rc \320 A Shell for Plan 9 and UNIX Systems)9 2230 1 1765 1230 t
10 I f
(Tom Duff)1 381 1 2689 1470 t
10 R f
(AT&T Bell Laboratories)2 993 1 2383 1650 t
(Murray Hill, New Jersey 07974)4 1267 1 2246 1770 t
10 I f
(ABSTRACT)2643 2150 w
(Rc)1330 2410 w
10 R f
( also runs on a variety of traditional sys-)8 1641( It)1 115( interpreter for Plan 9.)4 900(is a command)2 561 4 1463 2410 t
( provides similar facilities to Bourne's)5 1580( It)1 120( SunOS and the Tenth Edition.)5 1273(tems, including)1 627 4 1080 2530 t
10 I f
(/bin/sh)1080 2650 w
10 R f
( paper intro-)2 497( This)1 229(, with some small additions and mostly less idiosyncratic syntax.)9 2601 3 1353 2650 t
(duces)1080 2770 w
10 I f
(rc)1335 2770 w
10 R f
( why it varies)3 547('s highlights with numerous examples, and discusses its design and)9 2715 2 1418 2770 t
(from Bourne's.)1 610 1 1080 2890 t
10 B f
(1. Introduction)1 670 1 720 3250 t
10 R f
( new)1 208( porting the Bourne shell to an incompatible)7 1875( As)1 177(Plan 9 needs a command-programming language.)5 2060 4 720 3406 t
( new command interpreter, called)4 1350(environment seemed a daunting task, I chose to write a)9 2232 2 720 3526 t
10 I f
(rc)4330 3526 w
10 R f
(because it runs)2 599 1 4441 3526 t
( could hardly resist trying to)5 1220( tinkering with perfection is a dangerous business, I)8 2197(commands. Although)1 903 3 720 3646 t
( Thus)1 250(`improve' on Bourne's design.)3 1226 2 720 3766 t
10 I f
(rc)2221 3766 w
10 R f
(is similar in spirit but different in detail from Bourne's shell.)10 2424 1 2329 3766 t
(The bulk of this paper describes)5 1318 1 720 3922 t
10 I f
(rc)2071 3922 w
10 R f
( features with many small examples and a few larger ones.)10 2426('s principal)1 460 2 2154 3922 t
(We close with a discussion of the principles guiding)8 2143 1 720 4042 t
10 I f
(rc)2895 4042 w
10 R f
( it differs from Bourne's design.)5 1317('s design and why)3 745 2 2978 4042 t
( features, as individual details)4 1198(The descriptive sections include little discussion of the rationale for particular)10 3122 2 720 4162 t
( skip to the discussion at the end before)8 1632( impatient reader may wish to)5 1230( The)1 213(are hard to justify in isolation.)5 1245 4 720 4282 t
(skimming the expository parts of the paper.)6 1740 1 720 4402 t
10 B f
( commands)1 486(2. Simple)1 420 2 720 4642 t
10 R f
(For the simplest uses)3 881 1 720 4798 t
10 I f
(rc)1639 4798 w
10 R f
( all of the following behave as)6 1293( Thus)1 263(has syntax familiar to Bourne-shell users.)5 1724 3 1760 4798 t
(expected:)720 4918 w
9 CW f
(date)1008 5088 w
(con alice)1 486 1 1008 5198 t
(who >user.names)1 810 1 1008 5308 t
(who >>user.names)1 864 1 1008 5418 t
(wc <file)1 432 1 1008 5528 t
(echo [a-f]*.c)1 702 1 1008 5638 t
(who | wc)2 432 1 1008 5748 t
(who; date)1 486 1 1008 5858 t
(cc *.c &)2 432 1 1008 5968 t
(cyntax *.c && cc -g -o cmd *.c)7 1620 1 1008 6078 t
(is the name of the file from which)7 1356 1 2242 7002 t
10 I f
(rc)3623 7002 w
10 R f
('s input is being read.)4 863 1 3706 7002 t
cleartomark
showpage
saveobj restore
%%EndPage: 2 2
%%Page: 3 3
/saveobj save def
mark
3 pagesetup
10 R f
(- 3 -)2 166 1 2797 480 t
10 B f
(6. Concatenation)1 747 1 720 840 t
10 I f
(Rc)720 996 w
10 R f
(has a string concatenation operator, the caret)6 1781 1 850 996 t
10 CW f
(\303)2656 996 w
10 R f
(, to build arguments out of pieces.)6 1360 1 2716 996 t
9 CW f
(echo hully\303gully)1 864 1 1008 1166 t
10 R f
(is exactly equivalent to)3 924 1 720 1346 t
9 CW f
(echo hullygully)1 810 1 1008 1516 t
10 R f
(Suppose variable)1 685 1 720 1696 t
10 CW f
(i)1430 1696 w
10 R f
( Then)1 255(contains the name of a command.)5 1342 2 1515 1696 t
9 CW f
(cc -o $i $i\303.c)3 756 1 1008 1866 t
10 R f
(might compile the command's source code, leaving the result in the appropriate file.)12 3367 1 720 2046 t
(Concatenation distributes over lists. The following)5 2027 1 720 2202 t
9 CW f
(echo \(a b c\)\303\(1 2 3\))5 1080 1 1008 2372 t
(src=\(main subr io\))2 972 1 1008 2482 t
(cc $src\303.c)1 540 1 1008 2592 t
10 R f
(are equivalent to)2 665 1 720 2772 t
9 CW f
(echo a1 b2 c3)3 702 1 1008 2942 t
(cc main.c subr.c io.c)3 1134 1 1008 3052 t
10 R f
(In detail, the rule is: if both operands of)8 1640 1 720 3232 t
10 CW f
(\303)2392 3232 w
10 R f
( non-zero number of strings, they are con-)7 1735(are lists of the same)4 821 2 2484 3232 t
( if one of the operands is a single string, it is concatenated with each mem-)15 3059( Otherwise,)1 491(catenated pairwise.)1 770 3 720 3352 t
( other combination of operands is an error.)7 1702( Any)1 222(ber of the other operand in turn.)6 1272 3 720 3472 t
10 B f
( carets)1 279(7. Free)1 318 2 720 3712 t
10 R f
(User demand has dictated that)4 1263 1 720 3868 t
10 I f
(rc)2023 3868 w
10 R f
( syntax look more like the)5 1121(insert carets in certain places, to make the)7 1773 2 2146 3868 t
( example, this:)2 586( For)1 189(Bourne shell.)1 533 3 720 3988 t
9 CW f
(cc -$flags $stems.c)2 1026 1 1008 4158 t
10 R f
(is equivalent to)2 611 1 720 4338 t
9 CW f
(cc -\303$flags $stems\303.c)2 1134 1 1008 4508 t
10 R f
(In general,)1 440 1 720 4688 t
10 I f
(rc)1199 4688 w
10 R f
(will insert)1 417 1 1321 4688 t
10 CW f
(\303)1777 4688 w
10 R f
( Specifically,)1 567( not separated by white space.)5 1272(between two arguments that are)4 1325 3 1876 4688 t
(whenever one of)2 668 1 720 4808 t
10 CW f
($'`)1415 4808 w
10 R f
(follows a quoted or unquoted word, or an unquoted word follows a quoted word with)14 3418 1 1622 4808 t
(no intervening blanks or tabs, a)5 1264 1 720 4928 t
10 CW f
(\303)2011 4928 w
10 R f
( an unquoted word immediately following)5 1700( If)1 119( between the two.)3 713(is inserted)1 410 4 2098 4928 t
(a)720 5048 w
10 CW f
($)797 5048 w
10 R f
(contains a character other than an alphanumeric, underscore or)8 2564 1 890 5048 t
10 CW f
(*)3487 5048 w
10 R f
(, a)1 102 1 3547 5048 t
10 CW f
(\303)3682 5048 w
10 R f
( the first such)3 562(is inserted before)2 703 2 3775 5048 t
(character.)720 5168 w
10 B f
( substitution)1 532(8. Command)1 575 2 720 5408 t
10 R f
( list from the output of a command.)7 1444(It is often useful to build an argument)7 1528 2 720 5564 t
10 I f
(Rc)3746 5564 w
10 R f
(allows a command, enclosed)3 1160 1 3880 5564 t
(in braces and preceded by a left quote,)7 1569 1 720 5684 t
10 CW f
(`{...})2319 5684 w
10 R f
( command is)2 519( The)1 209( an argument is required.)4 1011(, anywhere that)2 622 4 2679 5684 t
( characters stored in the variable)5 1333( The)1 213( its standard output captured.)4 1189(executed and)1 530 4 720 5804 t
10 CW f
(ifs)4018 5804 w
10 R f
(are used to split the)4 809 1 4231 5804 t
( example,)1 388( For)1 189(output into arguments.)2 903 3 720 5924 t
9 CW f
(cat `{ls -tr|sed 10q})3 1134 1 1008 6094 t
10 R f
(will catenate the ten oldest files in the current directory in temporal order.)12 2947 1 720 6274 t
10 B f
( branching)1 465(9. Pipeline)1 470 2 720 6514 t
10 R f
( occasionally it is useful to have)6 1312( Very)1 254( for almost all cases.)4 838(The normal pipeline notation is general enough)6 1916 4 720 6670 t
( can require arbitrarily large pipe)5 1350( topologies more general than trees)5 1440( Pipeline)1 386(pipelines that are not linear.)4 1144 4 720 6790 t
(buffers, or worse, can cause deadlock.)5 1567 1 720 6910 t
10 I f
(Rc)2346 6910 w
10 R f
( of non-linear but treelike pipelines.)5 1481(has syntax for some kinds)4 1074 2 2485 6910 t
(For example,)1 527 1 720 7030 t
9 CW f
(cmp <{old} <{new})2 918 1 1440 7200 t
cleartomark
showpage
saveobj restore
%%EndPage: 3 3
%%Page: 4 4
/saveobj save def
mark
4 pagesetup
10 R f
(- 4 -)2 166 1 2797 480 t
(will regression test a new version of a command.)8 1963 1 720 840 t
10 CW f
(<)2734 840 w
10 R f
(or)2820 840 w
10 CW f
(>)2929 840 w
10 R f
( in braces causes the com-)5 1054(followed by a command)3 971 2 3015 840 t
( parent command \()3 751( The)1 205( be run with its standard output or input attached to a pipe.)12 2334(mand to)1 326 4 720 960 t
10 CW f
(cmp)4336 960 w
10 R f
(in the exam-)2 499 1 4541 960 t
( descriptor or other, and with an argument)7 1701(ple\) is started with the other end of the pipe attached to some file)13 2619 2 720 1080 t
( connect to the pipe when opened \(e.g.)7 1601(that will)1 341 2 720 1200 t
10 CW f
(/dev/fd/6)2721 1200 w
10 R f
( systems without)2 691(.\) On)1 239 2 3261 1200 t
10 CW f
(/dev/fd)4225 1200 w
10 R f
(or some-)1 361 1 4679 1200 t
(thing similar \(SunOS for example\) this feature does not work.)9 2475 1 720 1320 t
10 B f
( status)1 275(10. Exit)1 353 2 720 1560 t
10 R f
( Plan 9 status is a character)6 1153( On)1 184( executed it.)2 509(When a command exits it returns status to the program that)10 2474 4 720 1716 t
( normal termination it is empty.)5 1267( On)1 172(string describing an error condition.)4 1434 3 720 1836 t
10 I f
(Rc)720 1992 w
10 R f
( the variable)2 537(captures commands' exit statuses in)4 1521 2 871 1992 t
10 CW f
($status)2976 1992 w
10 R f
( a simple command the value of)6 1408(. For)1 236 2 3396 1992 t
10 CW f
($status)720 2112 w
10 R f
( a pipeline)2 420( For)1 191(is just as described above.)4 1048 3 1167 2112 t
10 CW f
($status)2853 2112 w
10 R f
( to the concatenation of the statuses of)7 1535(is set)1 205 2 3300 2112 t
(the pipeline components with)3 1180 1 720 2232 t
10 CW f
(|)1925 2232 w
10 R f
(characters for separators.)2 998 1 2010 2232 t
10 I f
(Rc)720 2388 w
10 R f
( control flow, many of them conditioned by the status returned from previously)12 3286(has a several kinds of)4 895 2 859 2388 t
( Any)1 224(executed commands.)1 839 2 720 2508 t
10 CW f
($status)1810 2508 w
10 R f
(containing only)1 627 1 2257 2508 t
10 CW f
(0)2911 2508 w
10 R f
('s and)1 243 1 2971 2508 t
10 CW f
(|)3241 2508 w
10 R f
('s has boolean value)3 818 1 3301 2508 t
10 I f
(true)4146 2508 w
10 R f
( other status)2 485(. Any)1 248 2 4307 2508 t
(is)720 2628 w
10 I f
(false)812 2628 w
10 R f
(.)1001 2628 w
10 B f
( grouping)1 415(11. Command)1 625 2 720 2868 t
10 R f
(A sequence of commands enclosed in)5 1505 1 720 3024 t
10 CW f
({})2250 3024 w
10 R f
( example:)1 391( For)1 189(may be used anywhere a command is required.)7 1873 3 2395 3024 t
9 CW f
({sleep 3600;echo 'Time''s up!'}&)3 1728 1 1008 3194 t
10 R f
( the braces:)2 454( Without)1 378(will wait an hour in the background, then print a message.)10 2319 3 720 3374 t
9 CW f
(sleep 3600;echo 'Time''s up!'&)3 1620 1 1008 3544 t
10 R f
(this would lock up the terminal for an hour, then print the message in the background!)15 3440 1 720 3724 t
10 B f
( flow \320)2 333(12. Control)1 508 2 720 3964 t
10 CW f
(for)1586 3964 w
10 R f
(A command may be executed once for each member of a list by typing, for example:)15 3387 1 720 4120 t
9 CW f
(for\(i in printf scanf putchar\) look $i /usr/td/lib/dw.dat)7 3078 1 1008 4290 t
10 R f
(This looks for each of the words)6 1292 1 720 4470 t
10 CW f
(printf)2037 4470 w
10 R f
(,)2397 4470 w
10 CW f
(scanf)2447 4470 w
10 R f
(and)2772 4470 w
10 CW f
(putchar)2941 4470 w
10 R f
( general form is)3 629( The)1 205(in the given file.)3 655 3 3386 4470 t
9 CW f
(for\()1008 4640 w
9 I f
(name)1224 4640 w
9 CW f
(in)1473 4640 w
9 I f
(list)1635 4640 w
9 CW f
(\))1745 4640 w
9 I f
(command)1853 4640 w
10 R f
(or)720 4820 w
9 CW f
(for\()1008 4990 w
9 I f
(name)1224 4990 w
9 CW f
(\))1419 4990 w
9 I f
(command)1527 4990 w
10 R f
( first case)2 394(In the)1 235 2 720 5170 t
10 I f
(command)1380 5170 w
10 R f
(is executed once for each member of)6 1503 1 1799 5170 t
10 I f
(list)3333 5170 w
10 R f
(with that member assigned to variable)5 1553 1 3487 5170 t
10 I f
(name)720 5290 w
10 R f
(. If)1 141 1 936 5290 t
10 CW f
(in)1102 5290 w
10 I f
(list)1247 5290 w
10 R f
(is not given,)2 492 1 1395 5290 t
10 I f
($*)1912 5290 w
10 R f
(is used.)1 300 1 2037 5290 t
10 B f
( execution \320)2 555(13. Conditional)1 682 2 720 5530 t
10 CW f
(if)1982 5530 w
10 I f
(Rc)720 5686 w
10 R f
( example:)1 391( For)1 189(also provides a general if-statement.)4 1444 3 850 5686 t
9 CW f
(if\(cyntax *.c\) cc -g -o cmd *.c)6 1674 1 1008 5856 t
(if\(test -f /tmp/$i\) echo $i already in /tmp)7 2322 1 1224 6436 t
(if not cp $i /tmp)4 918 1 1224 6546 t
(})1008 6656 w
10 R f
(This loops over each file in)5 1090 1 720 6836 t
10 CW f
($*)1835 6836 w
10 R f
(, copying to)2 475 1 1955 6836 t
10 CW f
(/tmp)2455 6836 w
10 R f
(those that do not already appear there, and printing a mes-)10 2320 1 2720 6836 t
(sage for those that do.)4 879 1 720 6956 t
cleartomark
showpage
saveobj restore
%%EndPage: 4 4
%%Page: 5 5
/saveobj save def
mark
5 pagesetup
10 R f
(- 5 -)2 166 1 2797 480 t
10 B f
( flow \320)2 333(14. Control)1 508 2 720 840 t
10 CW f
(while)1586 840 w
10 I f
(Rc)720 996 w
10 R f
('s while statement looks like this:)5 1342 1 825 996 t
9 CW f
(while\(newer subr.c subr.o\) sleep 5)4 1836 1 1008 1166 t
10 R f
(This waits until)2 623 1 720 1346 t
10 CW f
(subr.o)1368 1346 w
10 R f
(is newer than)2 532 1 1753 1346 t
10 CW f
(subr.c)2310 1346 w
10 R f
(\(presumably because the C compiler finished with it.\))7 2147 1 2695 1346 t
10 B f
( flow \320)2 333(15. Control)1 508 2 720 1586 t
10 CW f
(switch)1586 1586 w
10 I f
(Rc)720 1742 w
10 R f
( general form is)3 629( Its)1 150(provides a switch statement to do pattern-matching on arbitrary strings.)9 2852 3 850 1742 t
9 CW f
(switch\()1008 1912 w
9 I f
(word)1386 1912 w
9 CW f
(\){)1571 1912 w
(case)1008 2022 w
9 I f
(pattern ...)1 352 1 1278 2022 t
(commands)1224 2132 w
9 CW f
(case)1008 2242 w
9 I f
(pattern ...)1 352 1 1278 2242 t
(commands)1224 2352 w
9 CW f
(...)1008 2462 w
(})1008 2572 w
10 I f
(Rc)720 2752 w
10 R f
( are the same as)4 647( Patterns)1 376(attempts to match the word against the patterns in each case statement in turn.)13 3164 3 853 2752 t
(for filename matching, except that)4 1372 1 720 2872 t
10 CW f
(/)2117 2872 w
10 R f
(and the first characters of)4 1013 1 2202 2872 t
10 CW f
(.)3240 2872 w
10 R f
(and)3350 2872 w
10 CW f
(..)3519 2872 w
10 R f
(need not be matched explicitly.)4 1251 1 3689 2872 t
( to the next case \(or the end of the switch\) are)11 1864(If any pattern matches, the commands following that case up)9 2456 2 720 3028 t
( example,)1 388( For)1 189(executed, and execution of the switch is complete.)7 2010 3 720 3148 t
9 CW f
(switch\($#*\){)1008 3318 w
(case 1)1 324 1 1008 3428 t
(cat >>$1)1 432 1 1224 3538 t
(case 2)1 324 1 1008 3648 t
(cat >>$2 <$1)2 648 1 1224 3758 t
(case *)1 324 1 1008 3868 t
(echo 'Usage: append [from] to')4 1620 1 1224 3978 t
(})1008 4088 w
10 R f
( two, the first)3 536( With)1 251( with one file argument, it tacks standard input to its end.)11 2279( Called)1 311(is an append command.)3 943 5 720 4268 t
( other number elicits a usage message.)6 1533( Any)1 222(is appended to the second.)4 1051 3 720 4388 t
(The built-in)1 475 1 720 4544 t
10 CW f
(\304)1220 4544 w
10 R f
( arguments are a)3 659( Its)1 151( more concise than a switch.)5 1136(command also matches patterns, and is often)6 1789 4 1305 4544 t
( sets)1 181( It)1 118(string and a list of patterns.)5 1123 3 720 4664 t
10 CW f
($status)2173 4664 w
10 R f
(to true if and only if any of the patterns matches the string.)12 2416 1 2624 4664 t
(The following example processes option arguments for the)7 2349 1 720 4784 t
10 I f
(man)3094 4784 w
10 R f
(\(1\) command:)1 563 1 3266 4784 t
9 CW f
(opt=\(\))1008 4954 w
(while\(\304 $1 -* [1-9] 10\){)4 1296 1 1008 5064 t
(switch\($1\){)1224 5174 w
(case [1-9] 10)2 702 1 1224 5284 t
(sec=$1 secn=$1)1 756 1 1440 5394 t
(case -f)1 378 1 1224 5504 t
(c=f s=f)1 378 1 1440 5614 t
(case -[qwnt])1 648 1 1224 5724 t
(cmd=$1)1440 5834 w
(case -T*)1 432 1 1224 5944 t
(T=$1)1440 6054 w
(case -*)1 378 1 1224 6164 t
(opt=\($opt $1\))1 702 1 1440 6274 t
(})1224 6384 w
(shift)1224 6494 w
(})1008 6604 w
cleartomark
showpage
saveobj restore
%%EndPage: 5 5
%%Page: 6 6
/saveobj save def
mark
6 pagesetup
10 R f
(- 6 -)2 166 1 2797 480 t
10 B f
(16. Functions)1 598 1 720 840 t
10 R f
(Functions may be defined by typing)5 1441 1 720 996 t
9 CW f
(fn)1008 1166 w
9 I f
(name)1170 1166 w
9 CW f
({)1419 1166 w
9 I f
(commands)1527 1166 w
9 CW f
(})1966 1166 w
10 R f
(Subsequently, whenever a command named)4 1795 1 720 1346 t
10 I f
(name)2550 1346 w
10 R f
(is encountered, the remainder of the command's argu-)7 2238 1 2802 1346 t
( to)1 106(ment list will assigned)3 910 2 720 1466 t
10 CW f
($*)1764 1466 w
10 R f
(and)1912 1466 w
10 I f
(rc)2084 1466 w
10 R f
(will execute the)2 638 1 2195 1466 t
10 I f
(commands)2861 1466 w
10 R f
( value of)2 355(. The)1 233 2 3288 1466 t
10 CW f
($*)3904 1466 w
10 R f
(will be restored on com-)4 988 1 4052 1466 t
( example:)1 391(pletion. For)1 492 2 720 1586 t
9 CW f
(fn g {)2 324 1 1008 1756 t
(gre -e $1 *.[hcyl])3 972 1 1224 1866 t
(})1008 1976 w
10 R f
(defines)720 2156 w
10 CW f
(g)1033 2156 w
10 I f
(pattern)1118 2156 w
10 R f
(to look for occurrences of)4 1030 1 1432 2156 t
10 I f
(pattern)2487 2156 w
10 R f
(in all program source files in the current directory.)8 2015 1 2801 2156 t
(Function definitions are deleted by writing)5 1707 1 720 2312 t
9 CW f
(fn)1008 2482 w
9 I f
(name)1170 2482 w
10 R f
(with no function body.)3 911 1 720 2662 t
10 B f
( execution)1 430(17. Command)1 625 2 720 2902 t
10 R f
( very little about what)4 897(Up to now we've said)4 892 2 720 3058 t
10 I f
(rc)2539 3058 w
10 R f
( the command name)3 822( If)1 121(does to execute a simple command.)5 1445 3 2652 3058 t
(is the name of a function defined using)7 1570 1 720 3178 t
10 CW f
(fn)2317 3178 w
10 R f
( if it is the name of a built-)8 1082( Otherwise,)1 487(, the function is executed.)4 1034 3 2437 3178 t
(in command, the built-in is executed directly by)7 1964 1 720 3298 t
10 I f
(rc)2716 3298 w
10 R f
( if the name contains a)5 936(. Otherwise,)1 517 2 2799 3298 t
10 CW f
(/)4284 3298 w
10 R f
(, it is taken to be)5 696 1 4344 3298 t
(the name of a binary program and is executed using)9 2155 1 720 3418 t
10 I f
(exec)2910 3418 w
10 R f
( the name contains no)4 907(\(2\). If)1 267 2 3086 3418 t
10 CW f
(/)4294 3418 w
10 R f
(, then directories)2 686 1 4354 3418 t
(mentioned in the variable)3 1018 1 720 3538 t
10 CW f
($path)1763 3538 w
10 R f
(are searched until an executable file is found.)7 1806 1 2088 3538 t
(matches any single character, whereas)4 1525 1 970 4094 t
9 CW f
(\304 $1 '?')2 432 1 1258 4264 t
10 R f
(only matches a literal question mark.)5 1476 1 970 4444 t
10 B f
( I/O Redirection)2 694(19. Advanced)1 603 2 720 4684 t
10 I f
(Rc)720 4840 w
10 R f
( of file descriptors other than 0 and 1 \(standard input and output\) by specifying the file)16 3472(allows redirection)1 718 2 850 4840 t
(descriptor in square brackets)3 1144 1 720 4960 t
10 CW f
([ ])1 180 1 1889 4960 t
10 R f
(after the)1 329 1 2094 4960 t
10 CW f
(<)2448 4960 w
10 R f
(or)2533 4960 w
10 CW f
(>)2641 4960 w
10 R f
( example,)1 388(. For)1 214 2 2701 4960 t
9 CW f
(cc junk.c >[2]junk.diag)2 1242 1 1008 5130 t
10 R f
(saves the compiler's diagnostics in)4 1393 1 720 5310 t
10 CW f
(junk.diag)2138 5310 w
10 R f
(.)2678 5310 w
( replaced by a copy, in the sense of)8 1471(File descriptors may be)3 959 2 720 5466 t
10 I f
(dup)3184 5466 w
10 R f
(\(2\), of an already-open file by typing, for)7 1706 1 3334 5466 t
(example)720 5586 w
9 CW f
(cc junk.c >[2=1])2 864 1 1008 5756 t
10 R f
( in conjunction with other)4 1061( is more useful)3 609( It)1 117(This replaces file descriptor 2 with a copy of file descriptor 1.)11 2533 4 720 5936 t
(redirections, like this)2 841 1 720 6056 t
9 CW f
(cc junk.c >junk.out >[2=1])3 1404 1 1008 6226 t
10 R f
( descriptor 1 to)3 629(Redirections are evaluated from left to right, so this redirects file)10 2667 2 720 6406 t
10 CW f
(junk.out)4050 6406 w
10 R f
(, then points)2 510 1 4530 6406 t
( contrast,)1 366( By)1 167(file descriptor 2 at the same file.)6 1289 3 720 6526 t
9 CW f
(cc junk.c >[2=1] >junk.out)3 1404 1 1008 6696 t
10 R f
( \(presumably the terminal\), and then directs file)7 2000(Redirects file descriptor 2 to a copy of file descriptor 1)10 2320 2 720 6876 t
( the first case, standard and diagnostic output will be intermixed in)11 2686( In)1 135( at a file.)3 355(descriptor 1)1 477 4 720 6996 t
10 CW f
(junk.out)4400 6996 w
10 R f
(. In)1 160 1 4880 6996 t
(the second, diagnostic output will appear on the terminal, and standard output will be sent to the file.)17 4024 1 720 7116 t
( For)1 211( using the duplication notation with an empty right-hand side.)9 2664(File descriptors may be closed by)5 1445 3 720 7272 t
cleartomark
showpage
saveobj restore
%%EndPage: 7 7
%%Page: 8 8
/saveobj save def
mark
8 pagesetup
10 R f
(- 8 -)2 166 1 2797 480 t
(example,)720 840 w
9 CW f
(cc junk.c >[2=])2 810 1 1008 1010 t
10 R f
(will discard diagnostics from the compilation.)5 1838 1 720 1190 t
(Arbitrary file descriptors may be sent through a pipe by typing, for example)12 3031 1 720 1346 t
( that the output of)4 779( Note)1 261( the C compiler's output.)4 1065(This deletes those ever-so-annoying blank lines from)6 2215 4 720 1696 t
10 CW f
(grep)720 1816 w
10 R f
(still appears on file descriptor 1.)5 1287 1 985 1816 t
( a pipe to some file descriptor other than zero.)9 1871(Very occasionally you may wish to connect the input side of)10 2449 2 720 1972 t
(The notation)1 508 1 720 2092 t
9 CW f
(cmd1 |[5=19] cmd2)2 918 1 1008 2262 t
10 R f
(creates a pipeline with)3 895 1 720 2442 t
10 CW f
(cmd1)1640 2442 w
10 R f
('s file descriptor 5 connected through a pipe to)8 1863 1 1880 2442 t
10 CW f
(cmd2)3768 2442 w
10 R f
('s file descriptor 19.)3 804 1 4008 2442 t
10 B f
( documents)1 486(20. Here)1 385 2 720 2682 t
10 I f
(Rc)720 2838 w
10 R f
( to commands, as in this)5 982(procedures may include data, called ``here documents'', to be provided as input)11 3206 2 852 2838 t
(version of the)2 549 1 720 2958 t
10 I f
(tel)1294 2958 w
10 R f
(command)1419 2958 w
9 CW f
(for\(i\) grep $i <<!)3 972 1 1008 3128 t
(...)1008 3238 w
(nls 2T-402 2912)2 810 1 1008 3348 t
(norman 2C-514 2842)2 972 1 1008 3458 t
(pjw 2T-502 7214)2 810 1 1008 3568 t
(...)1008 3678 w
(!)1008 3788 w
10 R f
(A here document is introduced by the redirection symbol)8 2288 1 720 3968 t
10 CW f
(<<)3034 3968 w
10 R f
( by an arbitrary eof marker \()6 1141(, followed)1 406 2 3154 3968 t
10 CW f
(!)4701 3968 w
10 R f
(in the)1 227 1 4813 3968 t
( to a line containing only the eof marker are saved in a tempo-)13 2507( following the command, up)4 1142(example\). Lines)1 671 3 720 4088 t
(rary file that it connected to the command's standard input when it is run.)13 2935 1 720 4208 t
10 I f
(Rc)720 4364 w
10 R f
( following)1 414( The)1 205(does variable substitution in here documents.)5 1804 3 850 4364 t
10 I f
(subst)3298 4364 w
10 R f
(command:)3529 4364 w
9 CW f
(ed $3 <<EOF)2 594 1 1008 4534 t
(g/$1/s//$2/g)1008 4644 w
(w)1008 4754 w
(EOF)1008 4864 w
10 R f
( of)1 113(changes all occurrences)2 954 2 720 5044 t
10 CW f
($1)1817 5044 w
10 R f
(to)1967 5044 w
10 CW f
($2)2075 5044 w
10 R f
(in file)1 241 1 2225 5044 t
10 CW f
($3)2496 5044 w
10 R f
( include a literal)3 661(. To)1 191 2 2616 5044 t
10 CW f
($)3498 5044 w
10 R f
(in a here document, type)4 1004 1 3588 5044 t
10 CW f
($$)4622 5044 w
10 R f
( the)1 152(. If)1 146 2 4742 5044 t
(name of a variable is followed immediately by)7 1861 1 720 5164 t
10 CW f
(\303)2606 5164 w
10 R f
(, the caret is deleted.)4 820 1 2666 5164 t
( by enclosing the eof marker following)6 1643(Variable substitution can be entirely suppressed)5 1981 2 720 5320 t
10 CW f
(<<)4384 5320 w
10 R f
(in quotation)1 496 1 4544 5320 t
(marks.)720 5440 w
(Here documents may be provided on file descriptors other than 0 by typing, for example)14 3530 1 720 5596 t
9 CW f
(cmd <<[4]End)1 648 1 1008 5766 t
(...)1008 5876 w
(End)1008 5986 w
10 B f
(21. Signals)1 482 1 720 6286 t
10 I f
(Rc)720 6442 w
10 R f
( function with the name of)5 1067( A)1 124( an interrupt is received from the terminal.)7 1705(scripts normally terminate when)3 1293 4 851 6442 t
( the usual way, but called when)6 1268(a signal, in lower case, is defined in)7 1449 2 720 6562 t
10 I f
(rc)3464 6562 w
10 R f
( of inter-)2 353( Signals)1 347(receives the signal.)2 766 3 3574 6562 t
(est are:)1 285 1 720 6682 t
10 CW f
(sighup)720 6838 w
10 R f
( controlling teletype has disconnected from)5 1728(Hangup. The)1 546 2 970 6958 t
10 I f
(rc)3269 6958 w
10 R f
(.)3352 6958 w
10 CW f
(sigint)720 7114 w
10 R f
(The interrupt character \(usually ASCII del\) was typed on the controlling terminal.)11 3272 1 970 7234 t
cleartomark
showpage
saveobj restore
%%EndPage: 8 8
%%Page: 9 9
/saveobj save def
mark
9 pagesetup
10 R f
(- 9 -)2 166 1 2797 480 t
10 CW f
(sigquit)720 840 w
10 R f
(The quit character \(usually ASCII fs, ctrl-\\\) was typed on the controlling terminal.)12 3278 1 970 960 t
10 CW f
(sigterm)720 1116 w
10 R f
(This signal is normally sent by)5 1231 1 970 1236 t
10 I f
(kill)2226 1236 w
10 R f
(\(1\).)2354 1236 w
10 CW f
(sigexit)720 1392 w
10 R f
(An artificial signal sent when)4 1176 1 970 1512 t
10 I f
(rc)2171 1512 w
10 R f
(is about to exit.)3 617 1 2279 1512 t
(As an example,)2 618 1 720 1668 t
9 CW f
(fn sigint{)1 540 1 1008 1838 t
(rm /tmp/junk)1 648 1 1224 1948 t
(exit)1224 2058 w
(})1008 2168 w
10 R f
(sets a trap for the keyboard interrupt that removes a temporary file before exiting.)13 3259 1 720 2348 t
( routine is set to)4 651(Signals will be ignored if the signal)6 1434 2 720 2504 t
10 CW f
({})2833 2504 w
10 R f
( revert to their default behavior when their)7 1714(. Signals)1 373 2 2953 2504 t
(handlers' definitions are deleted.)3 1308 1 720 2624 t
10 B f
(22. Environment)1 742 1 720 2864 t
10 R f
( Plan 9, the environ-)4 817( On)1 173( is a list of name-value pairs made available to executing binaries.)11 2645(The environment)1 685 4 720 3020 t
( in a file system named)5 929(ment is stored)2 565 2 720 3140 t
10 CW f
(#e)2240 3140 w
10 R f
(, normally mounted on)3 914 1 2360 3140 t
10 CW f
(/env)3300 3140 w
10 R f
( value of each variable is stored)6 1269(. The)1 231 2 3540 3140 t
( is not quite as horrendous as it sounds,)8 1577( \(This)1 262(in a separate file, with components terminated by ASCII nuls.)9 2481 3 720 3260 t
( contents of)2 482( The)1 213( access is involved.\))3 828(the file system is maintained entirely in core, so no disk or network)12 2797 4 720 3380 t
10 CW f
(/env)720 3500 w
10 R f
(are shared on a per-process group basis)6 1579 1 987 3500 t
10 S f
(-)2593 3500 w
10 R f
( process group is created it effectively attaches)7 1885(when a new)2 480 2 2675 3500 t
10 CW f
(/env)720 3620 w
10 R f
( consequence of this organization is that)6 1603( A)1 122(to a new file system initialized with a copy of the old one.)12 2329 3 986 3620 t
(commands can change environment entries and see the changes reflected in)10 3014 1 720 3740 t
10 I f
(rc)3759 3740 w
10 R f
(.)3842 3740 w
( in the environment, although this could easily)7 1939(There is not currently a way on Plan 9 to place functions)11 2381 2 720 3896 t
(done by mounting another instance of)5 1537 1 720 4016 t
10 CW f
(#e)2287 4016 w
10 R f
( can be)2 290( problem is that currently there)5 1259( The)1 210(on another directory.)2 844 4 2437 4016 t
(only one instance of)3 807 1 720 4136 t
10 CW f
(#e)1552 4136 w
10 R f
(per process group.)2 734 1 1697 4136 t
10 B f
( Variables)1 436(23. Local)1 414 2 720 4376 t
10 R f
( assignment followed by a com-)5 1289( An)1 174( the duration of a single command.)6 1402(It is often useful to set a variable for)8 1455 4 720 4532 t
( example)1 363( For)1 189(mand has this effect.)3 826 3 720 4652 t
9 CW f
(a=global)1008 4822 w
(a=local echo $a)2 810 1 1008 4932 t
(echo $a)1 378 1 1008 5042 t
10 R f
(will print)1 370 1 720 5222 t
9 CW f
(local)1008 5392 w
(global)1008 5502 w
10 R f
(This works even for compound commands, like)6 1906 1 720 5682 t