1
0

rc 20 KB

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