rc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. .TH RC 1
  2. .SH NAME
  3. rc, cd, eval, exec, exit, flag, rfork, shift, wait, whatis, ., ~ \- command language
  4. .SH SYNOPSIS
  5. .B rc
  6. [
  7. .B -srdiIlxepvV
  8. ]
  9. [
  10. .B -c command
  11. ]
  12. [
  13. .I file
  14. [
  15. .I arg ...
  16. ]]
  17. .SH DESCRIPTION
  18. .I Rc
  19. is the Plan 9 shell.
  20. It executes command lines read from a terminal or a file or, with the
  21. .B -c
  22. flag, from
  23. .I rc's
  24. argument list.
  25. .SS Command Lines
  26. A command line is a sequence of commands, separated by ampersands or semicolons
  27. .RB ( &
  28. or
  29. .BR ; ),
  30. terminated by a newline.
  31. The commands are executed in sequence
  32. from left to right.
  33. .I Rc
  34. does not wait for a command followed by
  35. .B &
  36. to finish executing before starting
  37. the following command.
  38. Whenever a command followed by
  39. .B &
  40. is executed, its process id is assigned to the
  41. .I rc
  42. variable
  43. .BR $apid .
  44. Whenever a command
  45. .I not
  46. followed by
  47. .B &
  48. exits or is terminated, the
  49. .I rc
  50. variable
  51. .B $status
  52. gets the process's wait message (see
  53. .IR wait (2));
  54. it will be the null string if the command was successful.
  55. .PP
  56. A long command line may be continued on subsequent lines by typing
  57. a backslash
  58. .RB ( \e )
  59. followed by a newline.
  60. This sequence is treated as though it were a blank.
  61. Backslash is not otherwise a special character.
  62. .PP
  63. A number-sign
  64. .RB ( # )
  65. and any following characters up to (but not including) the next newline
  66. are ignored, except in quotation marks.
  67. .SS Simple Commands
  68. A simple command is a sequence of arguments interspersed with I/O redirections.
  69. If the first argument is the name of an
  70. .I rc
  71. function or of one of
  72. .I rc's
  73. built-in commands, it is executed by
  74. .IR rc .
  75. Otherwise if the name starts with a slash
  76. .RB ( / ),
  77. it must be the path name of the program to be executed.
  78. Names containing no initial slash are searched for in
  79. a list of directory names stored in
  80. .BR $path .
  81. The first executable file of the given name found
  82. in a directory in
  83. .B $path
  84. is the program to be executed.
  85. To be executable, the user must have execute permission (see
  86. .IR stat (2))
  87. and the file must be either an executable binary
  88. for the current machine's CPU type, or a shell script.
  89. Shell scripts begin with a line containing the full path name of a shell
  90. (usually
  91. .BR /bin/rc ),
  92. prefixed by
  93. .LR #! .
  94. .PP
  95. The first word of a simple command cannot be a keyword unless it is
  96. quoted or otherwise disguised.
  97. The keywords are
  98. .EX
  99. for in while if not switch fn ~ ! @
  100. .EE
  101. .SS Arguments and Variables
  102. A number of constructions may be used where
  103. .I rc's
  104. syntax requires an argument to appear.
  105. In many cases a construction's
  106. value will be a list of arguments rather than a single string.
  107. .PP
  108. The simplest kind of argument is the unquoted word:
  109. a sequence of one or more characters none of which is a blank, tab,
  110. newline, or any of the following:
  111. .EX
  112. # ; & | ^ $ = ` ' { } ( ) < >
  113. .EE
  114. An unquoted word that contains any of the characters
  115. .B *
  116. .B ?
  117. .B [
  118. is a pattern for matching against file names.
  119. The character
  120. .B *
  121. matches any sequence of characters,
  122. .B ?
  123. matches any single character, and
  124. .BI [ class ]
  125. matches any character in the
  126. .IR class .
  127. If the first character of
  128. .I class
  129. is
  130. .BR ~ ,
  131. the class is complemented.
  132. The
  133. .I class
  134. may also contain pairs of characters separated by
  135. .BR - ,
  136. standing for all characters lexically between the two.
  137. The character
  138. .B /
  139. must appear explicitly in a pattern, as must the
  140. first character of the path name components
  141. .B .
  142. and
  143. .BR .. .
  144. A pattern is replaced by a list of arguments, one for each path name matched,
  145. except that a pattern matching no names is not replaced by the empty list,
  146. but rather stands for itself.
  147. Pattern matching is done after all other
  148. operations.
  149. Thus,
  150. .EX
  151. x=/tmp echo $x^/*.c
  152. .EE
  153. matches
  154. .BR /tmp/*.c ,
  155. rather than matching
  156. .B "/*.c
  157. and then prefixing
  158. .BR /tmp .
  159. .PP
  160. A quoted word is a sequence of characters surrounded by single quotes
  161. .RB ( ' ).
  162. A single quote is represented in a quoted word by a pair of quotes
  163. .RB ( '' ).
  164. .PP
  165. Each of the following is an argument.
  166. .PD 0
  167. .HP
  168. .BI ( arguments )
  169. .br
  170. The value of a sequence of arguments enclosed in parentheses is
  171. a list comprising the members of each element of the sequence.
  172. Argument lists have no recursive structure, although their syntax may
  173. suggest it.
  174. The following are entirely equivalent:
  175. .EX
  176. echo hi there everybody
  177. ((echo) (hi there) everybody)
  178. .EE
  179. .HP
  180. .BI $ argument
  181. .HP
  182. .BI $ argument ( subscript )
  183. .br
  184. The
  185. .I argument
  186. after the
  187. .B $
  188. is the name of a variable whose value is substituted.
  189. Multiple levels
  190. of indirection are possible, but of questionable utility.
  191. Variable values
  192. are lists of strings.
  193. If
  194. .I argument
  195. is a number
  196. .IR n ,
  197. the value is the
  198. .IR n th
  199. element of
  200. .BR $* ,
  201. unless
  202. .B $*
  203. doesn't have
  204. .I n
  205. elements, in which case the value is empty.
  206. If
  207. .I argument
  208. is followed by a parenthesized list of subscripts, the
  209. value substituted is a list composed of the requested elements (origin 1).
  210. The parenthesis must follow the variable name with no spaces.
  211. Assignments to variables are described below.
  212. .HP
  213. .BI $# argument
  214. .br
  215. The value is the number of elements in the named variable.
  216. A variable
  217. never assigned a value has zero elements.
  218. .HP
  219. $"\c
  220. .I argument
  221. .br
  222. The value is a single string containing the components of the named variable
  223. separated by spaces. A variable with zero elements yields the empty string.
  224. .HP
  225. .BI `{ command }
  226. .br
  227. .I rc
  228. executes the
  229. .I command
  230. and reads its standard output, splitting it into a list of arguments,
  231. using characters in
  232. .B $ifs
  233. as separators.
  234. If
  235. .B $ifs
  236. is not otherwise set, its value is
  237. .BR "'\ \et\en'" .
  238. .HP
  239. .BI <{ command }
  240. .HP
  241. .BI >{ command }
  242. .br
  243. The
  244. .I command
  245. is executed asynchronously with its standard output or standard input
  246. connected to a pipe.
  247. The value of the argument is the name of a file
  248. referring to the other end of the pipe.
  249. This allows the construction of
  250. non-linear pipelines.
  251. For example, the following runs two commands
  252. .B old
  253. and
  254. .B new
  255. and uses
  256. .B cmp
  257. to compare their outputs
  258. .EX
  259. cmp <{old} <{new}
  260. .EE
  261. .HP
  262. .IB argument ^ argument
  263. .br
  264. The
  265. .B ^
  266. operator concatenates its two operands.
  267. If the two operands
  268. have the same number of components, they are concatenated pairwise.
  269. If not,
  270. then one operand must have one component, and the other must be non-empty,
  271. and concatenation is distributive.
  272. .PD
  273. .SS Free Carets
  274. In most circumstances,
  275. .I rc
  276. will insert the
  277. .B ^
  278. operator automatically between words that are not separated by white space.
  279. Whenever one of
  280. .B $
  281. .B '
  282. .B `
  283. follows a quoted or unquoted word or an unquoted word follows a quoted word
  284. with no intervening blanks or tabs,
  285. a
  286. .B ^
  287. is inserted between the two.
  288. If an unquoted word immediately follows a
  289. .BR $
  290. and contains a character other than an alphanumeric, underscore,
  291. or
  292. .BR * ,
  293. a
  294. .B ^
  295. is inserted before the first such character.
  296. Thus
  297. .IP
  298. .B cc -$flags $stem.c
  299. .LP
  300. is equivalent to
  301. .IP
  302. .B cc -^$flags $stem^.c
  303. .SS I/O Redirections
  304. The sequence
  305. .BI > file
  306. redirects the standard output file (file descriptor 1, normally the
  307. terminal) to the named
  308. .IR file ;
  309. .BI >> file
  310. appends standard output to the file.
  311. The standard input file (file descriptor 0, also normally the terminal)
  312. may be redirected from a file by the sequence
  313. .BI < file \f1,
  314. or from an inline `here document'
  315. by the sequence
  316. .BI << eof-marker\f1.
  317. The contents of a here document are lines of text taken from the command
  318. input stream up to a line containing nothing but the
  319. .IR eof-marker ,
  320. which may be either a quoted or unquoted word.
  321. If
  322. .I eof-marker
  323. is unquoted, variable names of the form
  324. .BI $ word
  325. have their values substituted from
  326. .I rc's
  327. environment.
  328. If
  329. .BI $ word
  330. is followed by a caret
  331. .RB ( ^ ),
  332. the caret is deleted.
  333. If
  334. .I eof-marker
  335. is quoted, no substitution occurs.
  336. .PP
  337. Redirections may be applied to a file-descriptor other than standard input
  338. or output by qualifying the redirection operator
  339. with a number in square brackets.
  340. For example, the diagnostic output (file descriptor 2)
  341. may be redirected by writing
  342. .BR "cc junk.c >[2]junk" .
  343. .PP
  344. A file descriptor may be redirected to an already open descriptor by writing
  345. .BI >[ fd0 = fd1 ]
  346. or
  347. .BI <[ fd0 = fd1 ]\f1.
  348. .I Fd1
  349. is a previously opened file descriptor and
  350. .I fd0
  351. becomes a new copy (in the sense of
  352. .IR dup (2))
  353. of it.
  354. A file descriptor may be closed by writing
  355. .BI >[ fd0 =]
  356. or
  357. .BI <[ fd0 =]\f1.
  358. .PP
  359. Redirections are executed from left to right.
  360. Therefore,
  361. .B cc junk.c >/dev/null >[2=1]
  362. and
  363. .B cc junk.c >[2=1] >/dev/null
  364. have different effects: the first puts standard output in
  365. .BR /dev/null
  366. and then puts diagnostic output in the same place, where the second
  367. directs diagnostic output to the terminal and sends standard output to
  368. .BR /dev/null .
  369. .SS Compound Commands
  370. A pair of commands separated by a pipe operator
  371. .RB ( | )
  372. is a command.
  373. The standard output of the left command is sent through a pipe
  374. to the standard input of the right command.
  375. The pipe operator may be decorated
  376. to use different file descriptors.
  377. .BI |[ fd ]
  378. connects the output end of the pipe to file descriptor
  379. .I fd
  380. rather than 1.
  381. .BI |[ fd0 = fd1 ]
  382. connects output to
  383. .I fd1
  384. of the left command and input to
  385. .I fd0
  386. of the right command.
  387. .PP
  388. A pair of commands separated by
  389. .B &&
  390. or
  391. .B ||
  392. is a command.
  393. In either case, the left command is executed and its exit status examined.
  394. If the operator is
  395. .B &&
  396. the right command is executed if the left command's status is null.
  397. .B ||
  398. causes the right command to be executed if the left command's status is non-null.
  399. .PP
  400. The exit status of a command may be inverted (non-null is changed to null, null
  401. is changed to non-null) by preceding it with a
  402. .BR ! .
  403. .PP
  404. The
  405. .B |
  406. operator has highest precedence, and is left-associative (i.e. binds tighter
  407. to the left than the right).
  408. .B !
  409. has intermediate precedence, and
  410. .B &&
  411. and
  412. .B ||
  413. have the lowest precedence.
  414. .PP
  415. The unary
  416. .B @
  417. operator, with precedence equal to
  418. .BR ! ,
  419. causes its operand to be executed in a subshell.
  420. .PP
  421. Each of the following is a command.
  422. .PD 0
  423. .HP
  424. .B if (
  425. .I list
  426. .B )
  427. .I command
  428. .br
  429. A
  430. .I list
  431. is a sequence of commands, separated by
  432. .BR & ,
  433. .BR ; ,
  434. or newline.
  435. It is executed and
  436. if its exit status is null, the
  437. .I command
  438. is executed.
  439. .HP
  440. .B if not
  441. .I command
  442. .br
  443. The immediately preceding command must have been
  444. .BI if( list )
  445. .IR command .
  446. If its condition was non-zero, the
  447. .I command
  448. is executed.
  449. .HP
  450. .BI for( name
  451. .B in
  452. .IB arguments )
  453. .I command
  454. .HP
  455. .BI for( name )
  456. .I command
  457. .br
  458. The
  459. .I command
  460. is executed once for each
  461. .IR argument
  462. with that argument assigned to
  463. .IR name .
  464. If the argument list is omitted,
  465. .B $*
  466. is used.
  467. .HP
  468. .BI while( list )
  469. .I command
  470. .br
  471. The
  472. .I list
  473. is executed repeatedly until its exit status is non-null.
  474. Each time it returns null status, the
  475. .I command
  476. is executed.
  477. An empty
  478. .I list
  479. is taken to give null status.
  480. .HP
  481. .BI "switch(" argument "){" list }
  482. .br
  483. The
  484. .IR list
  485. is searched for simple commands beginning with the word
  486. .BR case .
  487. (The search is only at the `top level' of the
  488. .IR list .
  489. That is,
  490. .B cases
  491. in nested constructs are not found.)
  492. .I Argument
  493. is matched against each word following
  494. .B case
  495. using the pattern-matching algorithm described above, except that
  496. .B /
  497. and the first characters of
  498. .B .
  499. and
  500. .B ..
  501. need not be matched explicitly.
  502. When a match is found, commands in the list are executed up to the next
  503. following
  504. .B case
  505. command (at the top level) or the closing brace.
  506. .HP
  507. .BI { list }
  508. .br
  509. Braces serve to alter the grouping of commands implied by operator
  510. priorities.
  511. The
  512. .I body
  513. is a sequence of commands separated by
  514. .BR & ,
  515. .BR ; ,
  516. or newline.
  517. .HP
  518. .BI "fn " name { list }
  519. .HP
  520. .BI "fn " name
  521. .br
  522. The first form defines a function with the given
  523. .IR name .
  524. Subsequently, whenever a command whose first argument is
  525. .I name
  526. is encountered, the current value of
  527. the remainder of the command's argument list will be assigned to
  528. .BR $* ,
  529. after saving its current value, and
  530. .I rc
  531. will execute the
  532. .IR list .
  533. The second form removes
  534. .IR name 's
  535. function definition.
  536. .HP
  537. .BI "fn " note { list }
  538. .br
  539. .HP
  540. .BI "fn " note
  541. .br
  542. A function with a special name will be called when
  543. .I rc
  544. receives a corresponding note; see
  545. .IR notify (2).
  546. The valid note names (and corresponding notes) are
  547. .B sighup
  548. .RB ( hangup ),
  549. .B sigint
  550. .RB ( interrupt ),
  551. .BR sigalrm
  552. .RB ( alarm ),
  553. and
  554. .B sigfpe
  555. (floating point trap).
  556. By default
  557. .I rc
  558. exits on receiving any signal, except when run interactively,
  559. in which case interrupts and quits normally cause
  560. .I rc
  561. to stop whatever it's doing and start reading a new command.
  562. The second form causes
  563. .I rc
  564. to handle a signal in the default manner.
  565. .I Rc
  566. recognizes an artificial note,
  567. .BR sigexit ,
  568. which occurs when
  569. .I rc
  570. is about to finish executing.
  571. .HP
  572. .IB name = "argument command"
  573. .br
  574. Any command may be preceded by a sequence of assignments
  575. interspersed with redirections.
  576. The assignments remain in effect until the end of the command, unless
  577. the command is empty (i.e. the assignments stand alone), in which case
  578. they are effective until rescinded by later assignments.
  579. .PD
  580. .SS Built-in Commands
  581. These commands are executed internally by
  582. .IR rc ,
  583. usually because their execution changes or depends on
  584. .IR rc 's
  585. internal state.
  586. .PD 0
  587. .HP
  588. .BI . " file ..."
  589. .br
  590. Execute commands from
  591. .IR file .
  592. .B $*
  593. is set for the duration to the remainder of the argument list following
  594. .IR file .
  595. .I File
  596. is searched for using
  597. .BR $path .
  598. .HP
  599. .BI builtin " command ..."
  600. .br
  601. Execute
  602. .I command
  603. as usual except that any function named
  604. .I command
  605. is ignored in favor of the built-in meaning.
  606. .HP
  607. .BI "cd [" dir "]"
  608. .br
  609. Change the current directory to
  610. .IR dir .
  611. The default argument is
  612. .BR $home .
  613. .I dir
  614. is searched for in each of the directories mentioned in
  615. .BR $cdpath .
  616. .HP
  617. .BI "eval [" "arg ..." "]"
  618. .br
  619. The arguments are concatenated separated by spaces into a single string,
  620. read as input to
  621. .IR rc ,
  622. and executed.
  623. .HP
  624. .BI "exec [" "command ..." "]"
  625. .br
  626. This instance of
  627. .I rc
  628. replaces itself with the given (non-built-in)
  629. .IR command .
  630. .HP
  631. .BI "flag " f " [+-]"
  632. .br
  633. Either set
  634. .RB ( + ),
  635. clear
  636. .RB ( - ),
  637. or test (neither
  638. .B +
  639. nor
  640. .BR - )
  641. the flag
  642. .IR f ,
  643. where
  644. .I f
  645. is a single character, one of the command line flags (see Invocation, below).
  646. .HP
  647. .BI "exit [" status "]"
  648. .br
  649. Exit with the given exit status.
  650. If none is given, the current value of
  651. .B $status
  652. is used.
  653. .HP
  654. .BR "rfork " [ nNeEsfFm ]
  655. .br
  656. Become a new process group using
  657. .BI rfork( flags )
  658. where
  659. .I flags
  660. is composed of the bitwise OR of the
  661. .B rfork
  662. flags specified by the option letters
  663. (see
  664. .IR fork (2)).
  665. If no
  666. .I flags
  667. are given, they default to
  668. .BR ens .
  669. The
  670. .I flags
  671. and their meanings are:
  672. .B n
  673. is
  674. .BR RFNAMEG ;
  675. .B N
  676. is
  677. .BR RFCNAMEG ;
  678. .B e
  679. is
  680. .BR RFENVG ;
  681. .B E
  682. is
  683. .BR RFCENVG ;
  684. .B s
  685. is
  686. .BR RFNOTEG ;
  687. .B f
  688. is
  689. .BR RFFDG ;
  690. .B F
  691. is
  692. .BR RFCFDG ;
  693. and
  694. .B m
  695. is
  696. .BR RFNOMNT .
  697. .HP
  698. .BI "shift [" n "]"
  699. .br
  700. Delete the first
  701. .IR n
  702. (default 1)
  703. elements of
  704. .BR $* .
  705. .HP
  706. .BI "wait [" pid "]"
  707. .br
  708. Wait for the process with the given
  709. .I pid
  710. to exit.
  711. If no
  712. .I pid
  713. is given, all outstanding processes are waited for.
  714. .HP
  715. .BI whatis " name ..."
  716. .br
  717. Print the value of each
  718. .I name
  719. in a form suitable for input to
  720. .IR rc .
  721. The output is
  722. an assignment to any variable,
  723. the definition of any function,
  724. a call to
  725. .B builtin
  726. for any built-in command, or
  727. the completed pathname of any executable file.
  728. .HP
  729. .BI ~ " subject pattern ..."
  730. .br
  731. The
  732. .I subject
  733. is matched against each
  734. .I pattern
  735. in sequence.
  736. If it matches any pattern,
  737. .B $status
  738. is set to zero.
  739. Otherwise,
  740. .B $status
  741. is set to one.
  742. Patterns are the same as for file name matching, except that
  743. .B /
  744. and the first character of
  745. .B .
  746. and
  747. .B ..
  748. need not be matched explicitly.
  749. The
  750. .I patterns
  751. are not subjected to
  752. file name matching before the
  753. .B ~
  754. command is executed, so they need not be enclosed in quotation marks.
  755. .PD
  756. .SS Environment
  757. The
  758. .I environment
  759. is a list of strings made available to executing binaries by the
  760. .B env
  761. device
  762. (see
  763. .IR env (3)).
  764. .I Rc
  765. creates an environment entry for each variable whose value is non-empty,
  766. and for each function.
  767. The string for a variable entry has the variable's name followed by
  768. .B =
  769. and its value.
  770. If the value has more than one component, these
  771. are separated by ctrl-a
  772. .RB ( '\e001' )
  773. characters.
  774. The string for a function is just the
  775. .I rc
  776. input that defines the function.
  777. The name of a function in the environment is the function name
  778. preceded by
  779. .LR fn# .
  780. .PP
  781. When
  782. .I rc
  783. starts executing it reads variable and function definitions from its
  784. environment.
  785. .SS Special Variables
  786. The following variables are set or used by
  787. .IR rc .
  788. .PD 0
  789. .TP \w'\fL$promptXX'u
  790. .B $*
  791. Set to
  792. .IR rc 's
  793. argument list during initialization.
  794. Whenever a
  795. .B .
  796. command or a function is executed, the current value is saved and
  797. .B $*
  798. receives the new argument list.
  799. The saved value is restored on completion of the
  800. .B .
  801. or function.
  802. .TP
  803. .B $apid
  804. Whenever a process is started asynchronously with
  805. .BR & ,
  806. .B $apid
  807. is set to its process id.
  808. .TP
  809. .B $home
  810. The default directory for
  811. .BR cd .
  812. .TP
  813. .B $ifs
  814. The input field separators used in backquote substitutions.
  815. If
  816. .B $ifs
  817. is not set in
  818. .IR rc 's
  819. environment, it is initialized to blank, tab and newline.
  820. .TP
  821. .B $path
  822. The search path used to find commands and input files
  823. for the
  824. .B .
  825. command.
  826. If not set in the environment, it is initialized by
  827. .BR "path=(.\ /bin)" .
  828. Its use is discouraged; instead use
  829. .IR bind (1)
  830. to build a
  831. .B /bin
  832. containing what's needed.
  833. .TP
  834. .B $pid
  835. Set during initialization to
  836. .IR rc 's
  837. process id.
  838. .TP
  839. .B $prompt
  840. When
  841. .I rc
  842. is run interactively, the first component of
  843. .B $prompt
  844. is printed before reading each command.
  845. The second component is printed whenever a newline is typed and more lines
  846. are required to complete the command.
  847. If not set in the environment, it is initialized by
  848. .BR "prompt=('%\ '\ '\ ')" .
  849. .TP
  850. .B $status
  851. Set to the wait message of the last-executed program.
  852. (unless started with
  853. .BR &).
  854. .B !
  855. and
  856. .B ~
  857. also change
  858. .BR $status .
  859. Its value is used to control execution in
  860. .BR && ,
  861. .BR || ,
  862. .B if
  863. and
  864. .B while
  865. commands.
  866. When
  867. .I rc
  868. exits at end-of-file of its input or on executing an
  869. .B exit
  870. command with no argument,
  871. .B $status
  872. is its exit status.
  873. .PD
  874. .SS Invocation
  875. If
  876. .I rc
  877. is started with no arguments it reads commands from standard input.
  878. Otherwise its first non-flag argument is the name of a file from which
  879. to read commands (but see
  880. .B -c
  881. below).
  882. Subsequent arguments become the initial value of
  883. .BR $* .
  884. .I Rc
  885. accepts the following command-line flags.
  886. .PD 0
  887. .TP \w'\fL-c\ \fIstring\fLXX'u
  888. .BI -c " string"
  889. Commands are read from
  890. .IR string .
  891. .TP
  892. .B -s
  893. Print out exit status after any command where the status is non-null.
  894. .TP
  895. .B -e
  896. Exit if
  897. .B $status
  898. is non-null after executing a simple command.
  899. .TP
  900. .B -i
  901. If
  902. .B -i
  903. is present, or
  904. .I rc
  905. is given no arguments and its standard input is a terminal,
  906. it runs interactively.
  907. Commands are prompted for using
  908. .BR $prompt .
  909. .TP
  910. .B -I
  911. Makes sure
  912. .I rc
  913. is not run interactively.
  914. .TP
  915. .B -l
  916. If
  917. .B -l
  918. is given or the first character of argument zero is
  919. .BR - ,
  920. .I rc
  921. reads commands from
  922. .BR $home/lib/profile ,
  923. if it exists, before reading its normal input.
  924. .TP
  925. .B -p
  926. A no-op.
  927. .TP
  928. .B -d
  929. A no-op.
  930. .TP
  931. .B -v
  932. Echo input on file descriptor 2 as it is read.
  933. .TP
  934. .B -x
  935. Print each simple command before executing it.
  936. .TP
  937. .B -r
  938. Print debugging information (internal form of commands
  939. as they are executed).
  940. .PD
  941. .SH SOURCE
  942. .B /sys/src/cmd/rc
  943. .SH "SEE ALSO"
  944. Tom Duff,
  945. ``Rc \- The Plan 9 Shell''.
  946. .SH BUGS
  947. There should be a way to match patterns against whole lists rather than
  948. just single strings.
  949. .br
  950. Using
  951. .B ~
  952. to check the value of
  953. .B $status
  954. changes
  955. .BR $status .
  956. .br
  957. Functions that use here documents don't work.
  958. .br
  959. Free carets don't get inserted next to keywords.