rc 20 KB

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