Annotation of researchv10dc/vol2/rc/rc.ms-1, revision 1.1.1.1

1.1       root        1: .so ../ADM/mac
                      2: .XX 18 309 "\f2Rc\fP \(em A Shell for Plan 9 and UNIX"
                      3: .de TP \" An indented paragraph describing some command, tagged with the command name
                      4: .IP "\\f(CW\\$1\\fR" 8
                      5: .if \\w'\\$1'-7n .br
                      6: ..
                      7: .TL
                      8: .I Rc " \(em A Shell for Plan 9 and UNIX
                      9: .AU
                     10: Tom Duff
                     11: .AI
                     12: .MH
                     13: .AB
                     14: .I Rc
                     15: is a command interpreter for Plan 9.
                     16: It also runs on a variety of UNIX systems,
                     17: including SunOS and the Tenth Edition.
                     18: Its spirit is very close Bourne's
                     19: .I /bin/sh ,
                     20: but its notation is less abstruse.
                     21: .LP
                     22: .I Rc
                     23: tries to fix a number of problems with the Bourne shell.
                     24: There is no macro-substitution \(em commands are not re-scanned
                     25: after values of variables are substituted.  This eliminates the
                     26: need for several types of quotation, all with different semantics,
                     27: and as a side-effect abolishes several important Bourne-shell security holes.
                     28: .LP
                     29: It's syntax is more regular and better suited to casual use,
                     30: resembling
                     31: .I C ,
                     32: or maybe
                     33: .I awk ,
                     34: rather than
                     35: .I "Algol 68" .
                     36: The grammar is described using
                     37: .I yacc ,
                     38: and so can be accurately documented and understood.
                     39: .LP
                     40: The design strives for simplicity without sacrificing
                     41: too much facility.
                     42: .AE
                     43: .NH 1
                     44: Introduction
                     45: .LP
                     46: Plan 9 needs a command-programming language.  As porting the
                     47: Bourne shell to a non-UNIX environment seemed a daunting task,
                     48: I chose to write a new command interpreter called
                     49: .I rc
                     50: because it runs commands.
                     51: Although tinkering with perfection is a dangerous business,
                     52: I could hardly resist trying to `improve' on Bourne's design.
                     53: Its most identifiable shortcoming is its macro-processor view
                     54: of variable substitution, as evidenced by the peculiar semantic difference between
                     55: .CW $*
                     56: and
                     57: .CW $@ ,
                     58: the three different types of quotation and the odd interpretation of
                     59: .CW IFS ,
                     60: among other things.  The order and manner in which parsing, parameter assignment,
                     61: breaking into words and parameter substitution occur is hard to learn,
                     62: and has subtle effects that are often not well-understood, especially by novices.
                     63: .LP
                     64: It is remarkable that in the four most recent editions of the UNIX
                     65: programmer's manual the Bourne shell grammar described in the manual page
                     66: does not admit the command
                     67: .CW who|wc .
                     68: This is surely an oversight, but it suggests something darker:
                     69: nobody really knows what the Bourne shell's grammar is.  Even examination
                     70: of the source code is little help.  The parser is implemented by recursive
                     71: descent, but the routines corresponding to the syntactic categories all
                     72: have a flag argument that subtly changes their operation depending on the
                     73: context.
                     74: .CW "LPLOG=$LPSPOOL/log/${LPDEST}.`set \`date\`;echo $1`
                     75: .LP
                     76: .I Rc 's
                     77: parser is implemented using
                     78: .I yacc ,
                     79: so I can say precisely what the grammar is \(em it's reproduced in the appendix.
                     80: Its lexical structure is harder to describe; I could not convince my users
                     81: to abandon some Bourne-isms that would have made lexical analysis as
                     82: straightforward as C's.
                     83: (Of course, having coerced me into muddying up the syntax, they complain
                     84: about its turbidity.)
                     85: .LP
                     86: .I Rc 's
                     87: semantics are not very different from Bourne's.  It still has
                     88: command and pattern substitution, redirection, pipelines, conditional execution,
                     89: .I while
                     90: and
                     91: .I for
                     92: loops and almost everything else.
                     93: .LP
                     94: Syntax is another matter.  The syntax of the simplest commands must be very simple.
                     95: I've taken it as given that the reflex cases, those situations in which the
                     96: commands roll off the fingertips, should be handled as Bourne did.  Thus,
                     97: you still type
                     98: .P1
                     99: rm -fr *
                    100: ls|wc
                    101: cat *.c >c.files
                    102: cyntax *.c && cc -g *.c
                    103: .P2
                    104: there is a tension between on the one hand wanting a
                    105: very simple syntax with no punctuation for simple commands, and on the other
                    106: hand wanting a more complex syntax to write more complicated stuff in
                    107: reasonable ways.  The Bourne shell is as good a compromise in this regard as
                    108: I've seen, but even it has a funny two-level syntax with one syntax for the
                    109: commands it executes (normal commands and flow of control stuff like if and
                    110: case) and another syntax for executing those commands (monstrosities like
                    111: ${foo:=`bar \`parp\``}.
                    112: no macros
                    113: security
                    114: C instead of Algol 68
                    115: yacc
                    116: .NH 1
                    117: References
                    118: .LP
                    119: .in+.5i
                    120: .ti-.5i
                    121: [1]
                    122: M. Beeler, W. Gosper et al,
                    123: \fIHakmem,\fP
                    124: MIT AI Lab memo #239,
                    125: 1973
                    126: .in -.5i
                    127: .BP
                    128: hi
                    129: .BP
                    130: there
                    131: .BP
                    132: there
                    133: .BP
                    134: hi
                    135: .BP
                    136: there
                    137: .BP
                    138: hi
                    139: .BP
                    140: there
                    141: .BP
                    142: there
                    143: .BP
                    144: hi
                    145: .BP
                    146: there
                    147: .BP
                    148: there
                    149: .BP
                    150: hi
                    151: .BP
                    152: there
                    153: .BP
                    154: there

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.