rc 19 KB

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