/contrib/tcsh/tcsh.man

https://bitbucket.org/freebsd/freebsd-head/ · Unknown · 5380 lines · 5380 code · 0 blank · 0 comment · 0 complexity · 4a9554cf24153eeee47c6bd56146c920 MD5 · raw file

Large files are truncated click here to view the full file

  1. .\" Copyright (c) 1980, 1990, 1993
  2. .\" The Regents of the University of California. All rights reserved.
  3. .\"
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\" notice, this list of conditions and the following disclaimer.
  9. .\" 2. Redistributions in binary form must reproduce the above copyright
  10. .\" notice, this list of conditions and the following disclaimer in the
  11. .\" documentation and/or other materials provided with the distribution.
  12. .\" 3. Neither the name of the University nor the names of its contributors
  13. .\" may be used to endorse or promote products derived from this software
  14. .\" without specific prior written permission.
  15. .\"
  16. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  17. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  20. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. .\" SUCH DAMAGE.
  27. .\"
  28. .\" Style notes for the tcsh man page:
  29. .\"
  30. .\" - Tags in lists are bold, except in the FILES section where they are
  31. .\" italic.
  32. .\"
  33. .\" - References are bold for section headings and environment and shell
  34. .\" variables and italic for commands (externals, builtins, aliases, and
  35. .\" editor commands) and arguments to commands.
  36. .\"
  37. .\" - Be careful with the .B and .I macros: they handle only a limited number
  38. .\" of words. Work around this with \fB and \fI, but only if absolutely
  39. .\" necessary, because tcsh.man2html uses .B/.I to find name anchors.
  40. .\"
  41. .\" - Indent in multiples of 4, usually 8.
  42. .\"
  43. .\" - Use `', not '' or "", except of course in shell syntax examples.
  44. .\" '' at the beginning of a line will vanish!
  45. .\"
  46. .\" - Use \-, not -.
  47. .\"
  48. .\" - Include the tilde when naming dot files. `~/.login', not `.login'.
  49. .\"
  50. .\" - Refer to external commands in man page format, e.g., `csh(1)'. However,
  51. .\" tcsh is `tcsh', not `tcsh(1)', because this is the tcsh man page (and
  52. .\" see the next note anyway).
  53. .\"
  54. .\" - Say `the shell', not `tcsh', unless distinguishing between tcsh and csh.
  55. .\"
  56. .\" - Say `shell variable'/`environment variable' instead of `variable'
  57. .\" and `builtin command'/`editor command' instead of `builtin' or `command'
  58. .\" unless the distinction is absolutely clear from context.
  59. .\"
  60. .\" - Use the simple present tense. `The shell uses', not `The shell will use'.
  61. .\"
  62. .\" - IMPORTANT: Cross-reference as much as possible. Commands, variables,
  63. .\" etc. in the reference section should be mentioned in the appropriate
  64. .\" descriptive section, or at least in the reference-section description
  65. .\" of another command (or whatever) which is mentioned in a description
  66. .\" section. Remember to note OS-specific things in "OS variant support",
  67. .\" new features in NEW FEATURES and referenced external commands in SEE
  68. .\" ALSO.
  69. .\"
  70. .\" - tcsh.man2html depends heavily on the specific nroff commands used in the
  71. .\" man page when the script was written. Please stick closely to the style
  72. .\" used here if you can. In particular, please don't use nroff commands
  73. .\" which aren't already used herein.
  74. .\"
  75. .TH TCSH 1 "14 February 2012" "Astron 6.18.01"
  76. .SH NAME
  77. tcsh \- C shell with file name completion and command line editing
  78. .SH SYNOPSIS
  79. .B tcsh \fR[\fB\-bcdefFimnqstvVxX\fR] [\fB\-Dname\fR[\fB=value\fR]] [arg ...]
  80. .br
  81. .B tcsh \-l
  82. .SH DESCRIPTION
  83. \fItcsh\fR is an enhanced but completely compatible version of the Berkeley
  84. UNIX C shell, \fIcsh\fR(1).
  85. It is a command language interpreter usable both as an interactive login
  86. shell and a shell script command processor.
  87. It includes a command-line editor (see \fBThe command-line editor\fR),
  88. programmable word completion (see \fBCompletion and listing\fR),
  89. spelling correction (see \fBSpelling correction\fR),
  90. a history mechanism (see \fBHistory substitution\fR),
  91. job control (see \fBJobs\fR)
  92. and a C-like syntax.
  93. The \fBNEW FEATURES\fR section describes major enhancements of \fItcsh\fR
  94. over \fIcsh\fR(1).
  95. Throughout this manual, features of
  96. \fItcsh\fR not found in most \fIcsh\fR(1) implementations
  97. (specifically, the 4.4BSD \fIcsh\fR)
  98. are labeled with `(+)', and features which are present in \fIcsh\fR(1)
  99. but not usually documented are labeled with `(u)'.
  100. .SS "Argument list processing"
  101. If the first argument (argument 0) to the shell is `\-' then it is a
  102. login shell. A login shell can be also specified by invoking the shell with
  103. the \fB\-l\fR flag as the only argument.
  104. .PP
  105. The rest of the flag arguments are interpreted as follows:
  106. .TP 4
  107. .B \-b
  108. Forces a ``break'' from option processing, causing any
  109. further shell arguments to be treated as non-option arguments. The remaining
  110. arguments will not be interpreted as shell options. This may be used to pass
  111. options to a shell script without confusion or possible subterfuge. The shell
  112. will not run a set-user ID script without this option.
  113. .TP 4
  114. .B \-c
  115. Commands are read from the following argument (which must be present, and
  116. must be a single argument),
  117. stored in the \fBcommand\fR shell variable for reference, and executed.
  118. Any remaining arguments are placed in the \fBargv\fR shell variable.
  119. .TP 4
  120. .B \-d
  121. The shell loads the directory stack from \fI~/.cshdirs\fR as described under
  122. \fBStartup and shutdown\fR, whether or not it is a login shell. (+)
  123. .TP 4
  124. .B \-D\fIname\fR[=\fIvalue\fR]
  125. Sets the environment variable \fIname\fR to \fIvalue\fR. (Domain/OS only) (+)
  126. .TP 4
  127. .B \-e
  128. The shell exits if any invoked command terminates abnormally or
  129. yields a non-zero exit status.
  130. .TP 4
  131. .B \-f
  132. The shell does not load any resource or startup files, or perform any
  133. command hashing, and thus starts faster.
  134. .TP 4
  135. .B \-F
  136. The shell uses \fIfork\fR(2) instead of \fIvfork\fR(2) to spawn processes. (+)
  137. .TP 4
  138. .B \-i
  139. The shell is interactive and prompts for its top-level input, even if
  140. it appears to not be a terminal. Shells are interactive without this option if
  141. their inputs and outputs are terminals.
  142. .TP 4
  143. .B \-l
  144. The shell is a login shell. Applicable only if \fB\-l\fR is the only
  145. flag specified.
  146. .TP 4
  147. .B \-m
  148. The shell loads \fI~/.tcshrc\fR even if it does not belong to the effective
  149. user. Newer versions of \fIsu\fR(1) can pass \fB\-m\fR to the shell. (+)
  150. .TP 4
  151. .B \-n
  152. The shell parses commands but does not execute them.
  153. This aids in debugging shell scripts.
  154. .TP 4
  155. .B \-q
  156. The shell accepts SIGQUIT (see \fBSignal handling\fR) and behaves when
  157. it is used under a debugger. Job control is disabled. (u)
  158. .TP 4
  159. .B \-s
  160. Command input is taken from the standard input.
  161. .TP 4
  162. .B \-t
  163. The shell reads and executes a single line of input. A `\\' may be used to
  164. escape the newline at the end of this line and continue onto another line.
  165. .TP 4
  166. .B \-v
  167. Sets the \fBverbose\fR shell variable, so that
  168. command input is echoed after history substitution.
  169. .TP 4
  170. .B \-x
  171. Sets the \fBecho\fR shell variable, so that commands are echoed
  172. immediately before execution.
  173. .TP 4
  174. .B \-V
  175. Sets the \fBverbose\fR shell variable even before executing \fI~/.tcshrc\fR.
  176. .TP 4
  177. .B \-X
  178. Is to \fB\-x\fR as \fB\-V\fR is to \fB\-v\fR.
  179. .TP 4
  180. .B \-\-help
  181. Print a help message on the standard output and exit. (+)
  182. .TP 4
  183. .B \-\-version
  184. Print the version/platform/compilation options on the standard output and exit.
  185. This information is also contained in the \fBversion\fR shell variable. (+)
  186. .PP
  187. After processing of flag arguments, if arguments remain but none of the
  188. \fB\-c\fR, \fB\-i\fR, \fB\-s\fR, or \fB\-t\fR options were given, the first
  189. argument is taken as the name of a file of commands, or ``script'', to
  190. be executed. The shell opens this file and saves its name for possible
  191. resubstitution by `$0'. Because many systems use either the standard
  192. version 6 or version 7 shells whose shell scripts are not compatible
  193. with this shell, the shell uses such a `standard' shell to execute a script
  194. whose first character is not a `#', i.e., that does not start with a
  195. comment.
  196. .PP
  197. Remaining arguments are placed in the \fBargv\fR shell variable.
  198. .SS "Startup and shutdown"
  199. A login shell begins by executing commands from the system files
  200. \fI/etc/csh.cshrc\fR and \fI/etc/csh.login\fR.
  201. It then executes commands from files in the user's \fBhome\fR directory:
  202. first \fI~/.tcshrc\fR (+)
  203. or, if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR,
  204. then \fI~/.history\fR (or the value of the \fBhistfile\fR shell variable),
  205. then \fI~/.login\fR,
  206. and finally \fI~/.cshdirs\fR (or the value of the \fBdirsfile\fR shell variable) (+).
  207. The shell may read \fI/etc/csh.login\fR before instead of after
  208. \fI/etc/csh.cshrc\fR, and \fI~/.login\fR before instead of after
  209. \fI~/.tcshrc\fR or \fI~/.cshrc\fR and \fI~/.history\fR, if so compiled;
  210. see the \fBversion\fR shell variable. (+)
  211. .PP
  212. Non-login shells read only \fI/etc/csh.cshrc\fR and \fI~/.tcshrc\fR
  213. or \fI~/.cshrc\fR on startup.
  214. .PP
  215. For examples of startup files, please consult
  216. \fIhttp://tcshrc.sourceforge.net\fR.
  217. .PP
  218. Commands like \fIstty\fR(1) and \fItset\fR(1),
  219. which need be run only once per login, usually go in one's \fI~/.login\fR file.
  220. Users who need to use the same set of files with both \fIcsh\fR(1) and
  221. \fItcsh\fR can have only a \fI~/.cshrc\fR which checks for the existence of the
  222. \fBtcsh\fR shell variable (q.v.) before using \fItcsh\fR-specific commands,
  223. or can have both a \fI~/.cshrc\fR and a \fI~/.tcshrc\fR which \fIsource\fRs
  224. (see the builtin command) \fI~/.cshrc\fR.
  225. The rest of this manual uses `\fI~/.tcshrc\fR' to mean `\fI~/.tcshrc\fR or,
  226. if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR'.
  227. .PP
  228. In the normal case, the shell begins reading commands from the terminal,
  229. prompting with `> '. (Processing of arguments and the use of the shell to
  230. process files containing command scripts are described later.)
  231. The shell repeatedly reads a line of command input, breaks it into words,
  232. places it on the command history list, parses it and executes each command
  233. in the line.
  234. .PP
  235. One can log out by typing `^D' on an empty line, `logout' or `login' or
  236. via the shell's autologout mechanism (see the \fBautologout\fR shell variable).
  237. When a login shell terminates it sets the \fBlogout\fR shell variable to
  238. `normal' or `automatic' as appropriate, then
  239. executes commands from the files
  240. \fI/etc/csh.logout\fR and \fI~/.logout\fR. The shell may drop DTR on logout
  241. if so compiled; see the \fBversion\fR shell variable.
  242. .PP
  243. The names of the system login and logout files vary from system to system for
  244. compatibility with different \fIcsh\fR(1) variants; see \fBFILES\fR.
  245. .SS Editing
  246. We first describe \fBThe command-line editor\fR.
  247. The \fBCompletion and listing\fR and \fBSpelling correction\fR sections
  248. describe two sets of functionality that are implemented as editor commands
  249. but which deserve their own treatment.
  250. Finally, \fBEditor commands\fR lists and describes
  251. the editor commands specific to the shell and their default bindings.
  252. .SS "The command-line editor (+)"
  253. Command-line input can be edited using key sequences much like those used in
  254. GNU Emacs or \fIvi\fR(1).
  255. The editor is active only when the \fBedit\fR shell variable is set, which
  256. it is by default in interactive shells.
  257. The \fIbindkey\fR builtin can display and change key bindings.
  258. Emacs-style key bindings are used by default
  259. (unless the shell was compiled otherwise; see the \fBversion\fR shell variable),
  260. but \fIbindkey\fR can change the key bindings to \fIvi\fR-style bindings en masse.
  261. .PP
  262. The shell always binds the arrow keys (as defined in the \fBTERMCAP\fR
  263. environment variable) to
  264. .PP
  265. .PD 0
  266. .RS +4
  267. .TP 8
  268. down
  269. \fIdown-history\fR
  270. .TP 8
  271. up
  272. \fIup-history\fR
  273. .TP 8
  274. left
  275. \fIbackward-char\fR
  276. .TP 8
  277. right
  278. \fIforward-char\fR
  279. .PD
  280. .RE
  281. .PP
  282. unless doing so would alter another single-character binding.
  283. One can set the arrow key escape sequences to the empty string with \fIsettc\fR
  284. to prevent these bindings.
  285. The ANSI/VT100 sequences for arrow keys are always bound.
  286. .PP
  287. Other key bindings are, for the most part, what Emacs and \fIvi\fR(1)
  288. users would expect and can easily be displayed by \fIbindkey\fR, so there
  289. is no need to list them here. Likewise, \fIbindkey\fR can list the editor
  290. commands with a short description of each.
  291. .PP
  292. Note that editor commands do not have the same notion of a ``word'' as does the
  293. shell. The editor delimits words with any non-alphanumeric characters not in
  294. the shell variable \fBwordchars\fR, while the shell recognizes only whitespace
  295. and some of the characters with special meanings to it, listed under
  296. \fBLexical structure\fR.
  297. .SS "Completion and listing (+)"
  298. The shell is often able to complete words when given a unique abbreviation.
  299. Type part of a word (for example `ls /usr/lost') and hit the tab key to
  300. run the \fIcomplete-word\fR editor command.
  301. The shell completes the filename `/usr/lost' to `/usr/lost+found/',
  302. replacing the incomplete word with the complete word in the input buffer.
  303. (Note the terminal `/'; completion adds a `/' to the
  304. end of completed directories and a space to the end of other completed words,
  305. to speed typing and provide a visual indicator of successful completion.
  306. The \fBaddsuffix\fR shell variable can be unset to prevent this.)
  307. If no match is found (perhaps `/usr/lost+found' doesn't exist),
  308. the terminal bell rings.
  309. If the word is already complete (perhaps there is a `/usr/lost' on your
  310. system, or perhaps you were thinking too far ahead and typed the whole thing)
  311. a `/' or space is added to the end if it isn't already there.
  312. .PP
  313. Completion works anywhere in the line, not at just the end; completed
  314. text pushes the rest of the line to the right. Completion in the middle of a word
  315. often results in leftover characters to the right of the cursor that need
  316. to be deleted.
  317. .PP
  318. Commands and variables can be completed in much the same way.
  319. For example, typing `em[tab]' would complete `em' to
  320. `emacs' if \fIemacs\fR were the only command on your system beginning with `em'.
  321. Completion can find a command in any directory in \fBpath\fR or if
  322. given a full pathname.
  323. Typing `echo $ar[tab]' would complete `$ar' to `$argv'
  324. if no other variable began with `ar'.
  325. .PP
  326. The shell parses the input buffer to determine whether the word you want to
  327. complete should be completed as a filename, command or variable.
  328. The first word in the buffer and the first word following
  329. `;', `|', `|&', `&&' or `||' is considered to be a command.
  330. A word beginning with `$' is considered to be a variable.
  331. Anything else is a filename. An empty line is `completed' as a filename.
  332. .PP
  333. You can list the possible completions of a word at any time by typing `^D'
  334. to run the \fIdelete-char-or-list-or-eof\fR editor command.
  335. The shell lists the possible completions using the \fIls\-F\fR builtin (q.v.)
  336. and reprints the prompt and unfinished command line, for example:
  337. .IP "" 4
  338. > ls /usr/l[^D]
  339. .br
  340. lbin/ lib/ local/ lost+found/
  341. .br
  342. > ls /usr/l
  343. .PP
  344. If the \fBautolist\fR shell variable is set, the shell lists the remaining
  345. choices (if any) whenever completion fails:
  346. .IP "" 4
  347. > set autolist
  348. .br
  349. > nm /usr/lib/libt[tab]
  350. .br
  351. libtermcap.a@ libtermlib.a@
  352. .br
  353. > nm /usr/lib/libterm
  354. .PP
  355. If \fBautolist\fR is set to `ambiguous', choices are listed only when
  356. completion fails and adds no new characters to the word being completed.
  357. .PP
  358. A filename to be completed can contain variables, your own or others' home
  359. directories abbreviated with `~' (see \fBFilename substitution\fR) and
  360. directory stack entries abbreviated with `='
  361. (see \fBDirectory stack substitution\fR). For example,
  362. .IP "" 4
  363. > ls ~k[^D]
  364. .br
  365. kahn kas kellogg
  366. .br
  367. > ls ~ke[tab]
  368. .br
  369. > ls ~kellogg/
  370. .PP
  371. or
  372. .IP "" 4
  373. > set local = /usr/local
  374. .br
  375. > ls $lo[tab]
  376. .br
  377. > ls $local/[^D]
  378. .br
  379. bin/ etc/ lib/ man/ src/
  380. .br
  381. > ls $local/
  382. .PP
  383. Note that variables can also be expanded explicitly with the
  384. \fIexpand-variables\fR editor command.
  385. .PP
  386. \fIdelete-char-or-list-or-eof\fR lists at only the end of the line;
  387. in the middle of a line it deletes the character under the cursor and
  388. on an empty line it logs one out or, if \fBignoreeof\fR is set, does nothing.
  389. `M-^D', bound to the editor command \fIlist-choices\fR, lists completion
  390. possibilities anywhere on a line, and \fIlist-choices\fR (or any one of the
  391. related editor commands that do or don't delete, list and/or log out,
  392. listed under \fIdelete-char-or-list-or-eof\fR) can be bound to `^D' with
  393. the \fIbindkey\fR builtin command if so desired.
  394. .PP
  395. The \fIcomplete-word-fwd\fR and \fIcomplete-word-back\fR editor commands
  396. (not bound to any keys by default) can be used to cycle up and down through
  397. the list of possible completions, replacing the current word with the next or
  398. previous word in the list.
  399. .PP
  400. The shell variable \fBfignore\fR can be set to a list of suffixes to be
  401. ignored by completion. Consider the following:
  402. .IP "" 4
  403. > ls
  404. .br
  405. Makefile condiments.h~ main.o side.c
  406. .br
  407. README main.c meal side.o
  408. .br
  409. condiments.h main.c~
  410. .br
  411. > set fignore = (.o \\~)
  412. .br
  413. > emacs ma[^D]
  414. .br
  415. main.c main.c~ main.o
  416. .br
  417. > emacs ma[tab]
  418. .br
  419. > emacs main.c
  420. .PP
  421. `main.c~' and `main.o' are ignored by completion (but not listing),
  422. because they end in suffixes in \fBfignore\fR.
  423. Note that a `\\' was needed in front of `~' to prevent it from being
  424. expanded to \fBhome\fR as described under \fBFilename substitution\fR.
  425. \fBfignore\fR is ignored if only one completion is possible.
  426. .PP
  427. If the \fBcomplete\fR shell variable is set to `enhance', completion
  428. 1) ignores case and 2) considers periods, hyphens and underscores
  429. (`.', `\-' and `_') to be word separators and hyphens and underscores to
  430. be equivalent. If you had the following files
  431. .IP "" 4
  432. comp.lang.c comp.lang.perl comp.std.c++
  433. .br
  434. comp.lang.c++ comp.std.c
  435. .PP
  436. and typed `mail \-f c.l.c[tab]', it would be completed to
  437. `mail \-f comp.lang.c', and ^D would list `comp.lang.c' and `comp.lang.c++'.
  438. `mail \-f c..c++[^D]' would list `comp.lang.c++' and `comp.std.c++'. Typing
  439. `rm a\-\-file[^D]' in the following directory
  440. .IP "" 4
  441. A_silly_file a-hyphenated-file another_silly_file
  442. .PP
  443. would list all three files, because case is ignored and hyphens and
  444. underscores are equivalent. Periods, however, are not equivalent to
  445. hyphens or underscores.
  446. .PP
  447. If the \fBcomplete\fR shell variable is set to `Enhance', completion
  448. ignores case and differences between a hyphen and an underscore word
  449. separator only when the user types a lowercase character or a hyphen.
  450. Entering an uppercase character or an underscore will not match the
  451. corresponding lowercase character or hyphen word separator.
  452. Typing `rm a\-\-file[^D]' in the directory of the previous example would
  453. still list all three files, but typing `rm A\-\-file' would match only
  454. `A_silly_file' and typing `rm a__file[^D]' would match just `A_silly_file'
  455. and `another_silly_file' because the user explicitly used an uppercase
  456. or an underscore character.
  457. .PP
  458. Completion and listing are affected by several other shell variables:
  459. \fBrecexact\fR can be set to complete on the shortest possible unique
  460. match, even if more typing might result in a longer match:
  461. .IP "" 4
  462. > ls
  463. .br
  464. fodder foo food foonly
  465. .br
  466. > set recexact
  467. .br
  468. > rm fo[tab]
  469. .PP
  470. just beeps, because `fo' could expand to `fod' or `foo', but if we type
  471. another `o',
  472. .IP "" 4
  473. > rm foo[tab]
  474. .br
  475. > rm foo
  476. .PP
  477. the completion completes on `foo', even though `food' and `foonly'
  478. also match.
  479. \fBautoexpand\fR can be set to run the \fIexpand-history\fR editor command
  480. before each completion attempt, \fBautocorrect\fR can be set to
  481. spelling-correct the word to be completed (see \fBSpelling correction\fR)
  482. before each completion attempt and \fBcorrect\fR can be set to complete
  483. commands automatically after one hits `return'.
  484. \fBmatchbeep\fR can be set to make completion beep or not beep in a variety
  485. of situations, and \fBnobeep\fR can be set to never beep at all.
  486. \fBnostat\fR can be set to a list of directories and/or patterns that
  487. match directories to prevent the completion mechanism from \fIstat\fR(2)ing
  488. those directories.
  489. \fBlistmax\fR and \fBlistmaxrows\fR can be set to limit the number of items
  490. and rows (respectively) that are listed without asking first.
  491. \fBrecognize_only_executables\fR can be set to make the shell list only
  492. executables when listing commands, but it is quite slow.
  493. .PP
  494. Finally, the \fIcomplete\fR builtin command can be used to tell the shell how
  495. to complete words other than filenames, commands and variables.
  496. Completion and listing do not work on glob-patterns (see \fBFilename substitution\fR),
  497. but the \fIlist-glob\fR and \fIexpand-glob\fR editor commands perform
  498. equivalent functions for glob-patterns.
  499. .SS "Spelling correction (+)"
  500. The shell can sometimes correct the spelling of filenames, commands and variable names
  501. as well as completing and listing them.
  502. .PP
  503. Individual words can be spelling-corrected with the \fIspell-word\fR
  504. editor command (usually bound to M-s and M-S)
  505. and the entire input buffer with \fIspell-line\fR (usually bound to M-$).
  506. The \fBcorrect\fR shell variable can be set to `cmd' to correct the
  507. command name or `all' to correct the entire line each time return is typed,
  508. and \fBautocorrect\fR can be set to correct the word to be completed
  509. before each completion attempt.
  510. .PP
  511. When spelling correction is invoked in any of these ways and
  512. the shell thinks that any part of the command line is misspelled,
  513. it prompts with the corrected line:
  514. .IP "" 4
  515. > set correct = cmd
  516. .br
  517. > lz /usr/bin
  518. .br
  519. CORRECT>ls /usr/bin (y|n|e|a)?
  520. .PP
  521. One can answer `y' or space to execute the corrected line,
  522. `e' to leave the uncorrected command in the input buffer,
  523. `a' to abort the command as if `^C' had been hit, and
  524. anything else to execute the original line unchanged.
  525. .PP
  526. Spelling correction recognizes user-defined completions (see the
  527. \fIcomplete\fR builtin command). If an input word in a position for
  528. which a completion is defined resembles a word in the completion list,
  529. spelling correction registers a misspelling and suggests the latter
  530. word as a correction. However, if the input word does not match any of
  531. the possible completions for that position, spelling correction does
  532. not register a misspelling.
  533. .PP
  534. Like completion, spelling correction works anywhere in the line,
  535. pushing the rest of the line to the right and possibly leaving
  536. extra characters to the right of the cursor.
  537. .PP
  538. Beware: spelling correction is not guaranteed to work the way one intends,
  539. and is provided mostly as an experimental feature.
  540. Suggestions and improvements are welcome.
  541. .SS "Editor commands (+)"
  542. `bindkey' lists key bindings and `bindkey \-l' lists and briefly describes
  543. editor commands.
  544. Only new or especially interesting editor commands are described here.
  545. See \fIemacs\fR(1) and \fIvi\fR(1) for descriptions of each editor's
  546. key bindings.
  547. .PP
  548. The character or characters to which each command is bound by default is
  549. given in parentheses. `^\fIcharacter\fR' means a control character and
  550. `M-\fIcharacter\fR' a meta character, typed as escape-\fIcharacter\fR
  551. on terminals without a meta key. Case counts, but commands that are bound
  552. to letters by default are bound to both lower- and uppercase letters for
  553. convenience.
  554. .TP 8
  555. .B complete-word \fR(tab)
  556. Completes a word as described under \fBCompletion and listing\fR.
  557. .TP 8
  558. .B complete-word-back \fR(not bound)
  559. Like \fIcomplete-word-fwd\fR, but steps up from the end of the list.
  560. .TP 8
  561. .B complete-word-fwd \fR(not bound)
  562. Replaces the current word with the first word in the list of possible
  563. completions. May be repeated to step down through the list.
  564. At the end of the list, beeps and reverts to the incomplete word.
  565. .TP 8
  566. .B complete-word-raw \fR(^X-tab)
  567. Like \fIcomplete-word\fR, but ignores user-defined completions.
  568. .TP 8
  569. .B copy-prev-word \fR(M-^_)
  570. Copies the previous word in the current line into the input buffer.
  571. See also \fIinsert-last-word\fR.
  572. .TP 8
  573. .B dabbrev-expand \fR(M-/)
  574. Expands the current word to the most recent preceding one for which
  575. the current is a leading substring, wrapping around the history list
  576. (once) if necessary.
  577. Repeating \fIdabbrev-expand\fR without any intervening typing
  578. changes to the next previous word etc., skipping identical matches
  579. much like \fIhistory-search-backward\fR does.
  580. .TP 8
  581. .B delete-char \fR(not bound)
  582. Deletes the character under the cursor.
  583. See also \fIdelete-char-or-list-or-eof\fR.
  584. .TP 8
  585. .B delete-char-or-eof \fR(not bound)
  586. Does \fIdelete-char\fR if there is a character under the cursor
  587. or \fIend-of-file\fR on an empty line.
  588. See also \fIdelete-char-or-list-or-eof\fR.
  589. .TP 8
  590. .B delete-char-or-list \fR(not bound)
  591. Does \fIdelete-char\fR if there is a character under the cursor
  592. or \fIlist-choices\fR at the end of the line.
  593. See also \fIdelete-char-or-list-or-eof\fR.
  594. .TP 8
  595. .B delete-char-or-list-or-eof \fR(^D)
  596. Does \fIdelete-char\fR if there is a character under the cursor,
  597. \fIlist-choices\fR at the end of the line
  598. or \fIend-of-file\fR on an empty line.
  599. See also those three commands, each of which does only a single action, and
  600. \fIdelete-char-or-eof\fR, \fIdelete-char-or-list\fR and \fIlist-or-eof\fR,
  601. each of which does a different two out of the three.
  602. .TP 8
  603. .B down-history \fR(down-arrow, ^N)
  604. Like \fIup-history\fR, but steps down, stopping at the original input line.
  605. .TP 8
  606. .B end-of-file \fR(not bound)
  607. Signals an end of file, causing the shell to exit unless the \fBignoreeof\fR
  608. shell variable (q.v.) is set to prevent this.
  609. See also \fIdelete-char-or-list-or-eof\fR.
  610. .TP 8
  611. .B expand-history \fR(M-space)
  612. Expands history substitutions in the current word.
  613. See \fBHistory substitution\fR.
  614. See also \fImagic-space\fR, \fItoggle-literal-history\fR and
  615. the \fBautoexpand\fR shell variable.
  616. .TP 8
  617. .B expand-glob \fR(^X-*)
  618. Expands the glob-pattern to the left of the cursor.
  619. See \fBFilename substitution\fR.
  620. .TP 8
  621. .B expand-line \fR(not bound)
  622. Like \fIexpand-history\fR, but
  623. expands history substitutions in each word in the input buffer.
  624. .TP 8
  625. .B expand-variables \fR(^X-$)
  626. Expands the variable to the left of the cursor.
  627. See \fBVariable substitution\fR.
  628. .TP 8
  629. .B history-search-backward \fR(M-p, M-P)
  630. Searches backwards through the history list for a command beginning with
  631. the current contents of the input buffer up to the cursor and copies it
  632. into the input buffer.
  633. The search string may be a glob-pattern (see \fBFilename substitution\fR)
  634. containing `*', `?', `[]' or `{}'.
  635. \fIup-history\fR and \fIdown-history\fR will proceed from the
  636. appropriate point in the history list.
  637. Emacs mode only.
  638. See also \fIhistory-search-forward\fR and \fIi-search-back\fR.
  639. .TP 8
  640. .B history-search-forward \fR(M-n, M-N)
  641. Like \fIhistory-search-backward\fR, but searches forward.
  642. .TP 8
  643. .B i-search-back \fR(not bound)
  644. Searches backward like \fIhistory-search-backward\fR, copies the first match
  645. into the input buffer with the cursor positioned at the end of the pattern,
  646. and prompts with `bck: ' and the first match. Additional characters may be
  647. typed to extend the search, \fIi-search-back\fR may be typed to continue
  648. searching with the same pattern, wrapping around the history list if
  649. necessary, (\fIi-search-back\fR must be bound to a
  650. single character for this to work) or one of the following special characters
  651. may be typed:
  652. .PP
  653. .RS +8
  654. .RS +4
  655. .PD 0
  656. .TP 8
  657. ^W
  658. Appends the rest of the word under the cursor to the search pattern.
  659. .TP 8
  660. delete (or any character bound to \fIbackward-delete-char\fR)
  661. Undoes the effect of the last character typed and deletes a character
  662. from the search pattern if appropriate.
  663. .TP 8
  664. ^G
  665. If the previous search was successful, aborts the entire search.
  666. If not, goes back to the last successful search.
  667. .TP 8
  668. escape
  669. Ends the search, leaving the current line in the input buffer.
  670. .RE
  671. .PD
  672. .PP
  673. Any other character not bound to \fIself-insert-command\fR terminates the
  674. search, leaving the current line in the input buffer, and
  675. is then interpreted as normal input. In particular, a carriage return
  676. causes the current line to be executed.
  677. Emacs mode only.
  678. See also \fIi-search-fwd\fR and \fIhistory-search-backward\fR.
  679. .RE
  680. .TP 8
  681. .B i-search-fwd \fR(not bound)
  682. Like \fIi-search-back\fR, but searches forward.
  683. .TP 8
  684. .B insert-last-word \fR(M-_)
  685. Inserts the last word of the previous input line (`!$') into the input buffer.
  686. See also \fIcopy-prev-word\fR.
  687. .TP 8
  688. .B list-choices \fR(M-^D)
  689. Lists completion possibilities as described under \fBCompletion and listing\fR.
  690. See also \fIdelete-char-or-list-or-eof\fR and \fIlist-choices-raw\fR.
  691. .TP 8
  692. .B list-choices-raw \fR(^X-^D)
  693. Like \fIlist-choices\fR, but ignores user-defined completions.
  694. .TP 8
  695. .B list-glob \fR(^X-g, ^X-G)
  696. Lists (via the \fIls\-F\fR builtin) matches to the glob-pattern
  697. (see \fBFilename substitution\fR) to the left of the cursor.
  698. .TP 8
  699. .B list-or-eof \fR(not bound)
  700. Does \fIlist-choices\fR
  701. or \fIend-of-file\fR on an empty line.
  702. See also \fIdelete-char-or-list-or-eof\fR.
  703. .TP 8
  704. .B magic-space \fR(not bound)
  705. Expands history substitutions in the current line,
  706. like \fIexpand-history\fR, and inserts a space.
  707. \fImagic-space\fR is designed to be bound to the space bar,
  708. but is not bound by default.
  709. .TP 8
  710. .B normalize-command \fR(^X-?)
  711. Searches for the current word in PATH and, if it is found, replaces it with
  712. the full path to the executable. Special characters are quoted. Aliases are
  713. expanded and quoted but commands within aliases are not. This command is
  714. useful with commands that take commands as arguments, e.g., `dbx' and `sh \-x'.
  715. .TP 8
  716. .B normalize-path \fR(^X-n, ^X-N)
  717. Expands the current word as described under the `expand' setting
  718. of the \fBsymlinks\fR shell variable.
  719. .TP 8
  720. .B overwrite-mode \fR(unbound)
  721. Toggles between input and overwrite modes.
  722. .TP 8
  723. .B run-fg-editor \fR(M-^Z)
  724. Saves the current input line and
  725. looks for a stopped job with a name equal to the last component of the
  726. file name part of the \fBEDITOR\fR or \fBVISUAL\fR environment variables,
  727. or, if neither is set, `ed' or `vi'.
  728. If such a job is found, it is restarted as if `fg %\fIjob\fR' had been
  729. typed. This is used to toggle back and forth between an editor and
  730. the shell easily. Some people bind this command to `^Z' so they
  731. can do this even more easily.
  732. .TP
  733. .B run-help \fR(M-h, M-H)
  734. Searches for documentation on the current command, using the same notion of
  735. `current command' as the completion routines, and prints it. There is no way
  736. to use a pager; \fIrun-help\fR is designed for short help files.
  737. If the special alias \fBhelpcommand\fR is defined, it is run with the
  738. command name as a sole argument. Else,
  739. documentation should be in a file named \fIcommand\fR.help, \fIcommand\fR.1,
  740. \fIcommand\fR.6, \fIcommand\fR.8 or \fIcommand\fR, which should be in one
  741. of the directories listed in the \fBHPATH\fR environment variable.
  742. If there is more than one help file only the first is printed.
  743. .TP 8
  744. .B self-insert-command \fR(text characters)
  745. In insert mode (the default), inserts the typed character into the input line after the character under the cursor.
  746. In overwrite mode, replaces the character under the cursor with the typed character.
  747. The input mode is normally preserved between lines, but the
  748. \fBinputmode\fR shell variable can be set to `insert' or `overwrite' to put the
  749. editor in that mode at the beginning of each line.
  750. See also \fIoverwrite-mode\fR.
  751. .TP 8
  752. .B sequence-lead-in \fR(arrow prefix, meta prefix, ^X)
  753. Indicates that the following characters are part of a
  754. multi-key sequence. Binding a command to a multi-key sequence really creates
  755. two bindings: the first character to \fIsequence-lead-in\fR and the
  756. whole sequence to the command. All sequences beginning with a character
  757. bound to \fIsequence-lead-in\fR are effectively bound to \fIundefined-key\fR
  758. unless bound to another command.
  759. .TP 8
  760. .B spell-line \fR(M-$)
  761. Attempts to correct the spelling of each word in the input buffer, like
  762. \fIspell-word\fR, but ignores words whose first character is one of
  763. `\-', `!', `^' or `%', or which contain `\\', `*' or `?', to avoid problems
  764. with switches, substitutions and the like.
  765. See \fBSpelling correction\fR.
  766. .TP 8
  767. .B spell-word \fR(M-s, M-S)
  768. Attempts to correct the spelling of the current word as described
  769. under \fBSpelling correction\fR.
  770. Checks each component of a word which appears to be a pathname.
  771. .TP 8
  772. .B toggle-literal-history \fR(M-r, M-R)
  773. Expands or `unexpands' history substitutions in the input buffer.
  774. See also \fIexpand-history\fR and the \fBautoexpand\fR shell variable.
  775. .TP 8
  776. .B undefined-key \fR(any unbound key)
  777. Beeps.
  778. .TP 8
  779. .B up-history \fR(up-arrow, ^P)
  780. Copies the previous entry in the history list into the input buffer.
  781. If \fBhistlit\fR is set, uses the literal form of the entry.
  782. May be repeated to step up through the history list, stopping at the top.
  783. .TP 8
  784. .B vi-search-back \fR(?)
  785. Prompts with `?' for a search string (which may be a glob-pattern, as with
  786. \fIhistory-search-backward\fR), searches for it and copies it into the
  787. input buffer. The bell rings if no match is found.
  788. Hitting return ends the search and leaves the last match in the input
  789. buffer.
  790. Hitting escape ends the search and executes the match.
  791. \fIvi\fR mode only.
  792. .TP 8
  793. .B vi-search-fwd \fR(/)
  794. Like \fIvi-search-back\fR, but searches forward.
  795. .TP 8
  796. .B which-command \fR(M-?)
  797. Does a \fIwhich\fR (see the description of the builtin command) on the
  798. first word of the input buffer.
  799. .TP 8
  800. .B yank-pop \fR(M-y)
  801. When executed immediately after a \fIyank\fR or another \fIyank-pop\fR,
  802. replaces the yanked string with the next previous string from the
  803. killring. This also has the effect of rotating the killring, such that
  804. this string will be considered the most recently killed by a later
  805. \fIyank\fR command. Repeating \fIyank-pop\fR will cycle through the
  806. killring any number of times.
  807. .SS "Lexical structure"
  808. The shell splits input lines into words at blanks and tabs. The special
  809. characters `&', `|', `;', `<', `>', `(', and `)' and the doubled characters
  810. `&&', `||', `<<' and `>>' are always separate words, whether or not they are
  811. surrounded by whitespace.
  812. .PP
  813. When the shell's input is not a terminal, the character `#' is taken to begin a
  814. comment. Each `#' and the rest of the input line on which it appears is
  815. discarded before further parsing.
  816. .PP
  817. A special character (including a blank or tab) may be prevented from having
  818. its special meaning, and possibly made part of another word, by preceding it
  819. with a backslash (`\\') or enclosing it in single (`''), double (`"') or
  820. backward (``') quotes. When not otherwise quoted a newline preceded by a `\\'
  821. is equivalent to a blank, but inside quotes this sequence results in a
  822. newline.
  823. .PP
  824. Furthermore, all \fBSubstitutions\fR (see below) except \fBHistory substitution\fR
  825. can be prevented by enclosing the strings (or parts of strings)
  826. in which they appear with single quotes or by quoting the crucial character(s)
  827. (e.g., `$' or ``' for \fBVariable substitution\fR or \fBCommand substitution\fR respectively)
  828. with `\\'. (\fBAlias substitution\fR is no exception: quoting in any way any
  829. character of a word for which an \fIalias\fR has been defined prevents
  830. substitution of the alias. The usual way of quoting an alias is to precede it
  831. with a backslash.) \fBHistory substitution\fR is prevented by
  832. backslashes but not by single quotes. Strings quoted with double or backward
  833. quotes undergo \fBVariable substitution\fR and \fBCommand substitution\fR, but other
  834. substitutions are prevented.
  835. .PP
  836. Text inside single or double quotes becomes a single word (or part of one).
  837. Metacharacters in these strings, including blanks and tabs, do not form
  838. separate words. Only in one special case (see \fBCommand substitution\fR
  839. below) can a double-quoted string yield parts of more than one word;
  840. single-quoted strings never do. Backward quotes are special: they signal
  841. \fBCommand substitution\fR (q.v.), which may result in more than one word.
  842. .PP
  843. Quoting complex strings, particularly strings which themselves contain quoting
  844. characters, can be confusing. Remember that quotes need not be used as they are
  845. in human writing! It may be easier to quote not an entire string, but only
  846. those parts of the string which need quoting, using different types of quoting
  847. to do so if appropriate.
  848. .PP
  849. The \fBbackslash_quote\fR shell variable (q.v.) can be set to make backslashes
  850. always quote `\\', `'', and `"'. (+) This may make complex quoting tasks
  851. easier, but it can cause syntax errors in \fIcsh\fR(1) scripts.
  852. .SS Substitutions
  853. We now describe the various transformations the shell performs on the input in
  854. the order in which they occur. We note in passing the data structures involved
  855. and the commands and variables which affect them. Remember that substitutions
  856. can be prevented by quoting as described under \fBLexical structure\fR.
  857. .SS "History substitution"
  858. Each command, or ``event'', input from the terminal is saved in the history
  859. list. The previous command is always saved, and the \fBhistory\fR shell
  860. variable can be set to a number to save that many commands. The \fBhistdup\fR
  861. shell variable can be set to not save duplicate events or consecutive duplicate
  862. events.
  863. .PP
  864. Saved commands are numbered sequentially from 1 and stamped with the time.
  865. It is not usually necessary to use event numbers, but the current event number
  866. can be made part of the prompt by placing an `!' in the \fBprompt\fR shell variable.
  867. .PP
  868. The shell actually saves history in expanded and literal (unexpanded) forms.
  869. If the \fBhistlit\fR shell variable is set, commands that display and store
  870. history use the literal form.
  871. .PP
  872. The \fIhistory\fR builtin command can print, store in a file, restore
  873. and clear the history list at any time,
  874. and the \fBsavehist\fR and \fBhistfile\fR shell variables can be set to
  875. store the history list automatically on logout and restore it on login.
  876. .PP
  877. History substitutions introduce words from the history list into the input
  878. stream, making it easy to repeat commands, repeat arguments of a previous
  879. command in the current command, or fix spelling mistakes in the previous
  880. command with little typing and a high degree of confidence.
  881. .PP
  882. History substitutions begin with the character `!'. They may begin anywhere in
  883. the input stream, but they do not nest. The `!' may be preceded by a `\\' to
  884. prevent its special meaning; for convenience, a `!' is passed unchanged when it
  885. is followed by a blank, tab, newline, `=' or `('. History substitutions also
  886. occur when an input line begins with `^'. This special abbreviation will be
  887. described later. The characters used to signal history substitution (`!' and
  888. `^') can be changed by setting the \fBhistchars\fR shell variable. Any input
  889. line which contains a history substitution is printed before it is executed.
  890. .PP
  891. A history substitution may have an ``event specification'', which indicates
  892. the event from which words are to be taken, a ``word designator'',
  893. which selects particular words from the chosen event, and/or a ``modifier'',
  894. which manipulates the selected words.
  895. .PP
  896. An event specification can be
  897. .PP
  898. .PD 0
  899. .RS +4
  900. .TP 8
  901. .I n
  902. A number, referring to a particular event
  903. .TP 8
  904. \-\fIn\fR
  905. An offset, referring to the event \fIn\fR before the current event
  906. .TP 8
  907. #
  908. The current event.
  909. This should be used carefully in \fIcsh\fR(1), where there is no check for
  910. recursion. \fItcsh\fR allows 10 levels of recursion. (+)
  911. .TP 8
  912. !
  913. The previous event (equivalent to `\-1')
  914. .TP 8
  915. .I s
  916. The most recent event whose first word begins with the string \fIs\fR
  917. .TP 8
  918. ?\fIs\fR?
  919. The most recent event which contains the string \fIs\fR.
  920. The second `?' can be omitted if it is immediately followed by a newline.
  921. .RE
  922. .PD
  923. .PP
  924. For example, consider this bit of someone's history list:
  925. .IP "" 4
  926. \ 9 8:30 nroff \-man wumpus.man
  927. .br
  928. 10 8:31 cp wumpus.man wumpus.man.old
  929. .br
  930. 11 8:36 vi wumpus.man
  931. .br
  932. 12 8:37 diff wumpus.man.old wumpus.man
  933. .PP
  934. The commands are shown with their event numbers and time stamps.
  935. The current event, which we haven't typed in yet, is event 13.
  936. `!11' and `!\-2' refer to event 11.
  937. `!!' refers to the previous event, 12. `!!' can be abbreviated `!' if it is
  938. followed by `:' (`:' is described below).
  939. `!n' refers to event 9, which begins with `n'.
  940. `!?old?' also refers to event 12, which contains `old'.
  941. Without word designators or modifiers history references simply expand to the
  942. entire event, so we might type `!cp' to redo the copy command or `!!|more'
  943. if the `diff' output scrolled off the top of the screen.
  944. .PP
  945. History references may be insulated from the surrounding text with braces if
  946. necessary. For example, `!vdoc' would look for a command beginning with
  947. `vdoc', and, in this example, not find one, but `!{v}doc' would expand
  948. unambiguously to `vi wumpus.mandoc'.
  949. Even in braces, history substitutions do not nest.
  950. .PP
  951. (+) While \fIcsh\fR(1) expands, for example, `!3d' to event 3 with the
  952. letter `d' appended to it, \fItcsh\fR expands it to the last event beginning
  953. with `3d'; only completely numeric arguments are treated as event numbers.
  954. This makes it possible to recall events beginning with numbers.
  955. To expand `!3d' as in \fIcsh\fR(1) say `!{3}d'.
  956. .PP
  957. To select words from an event we can follow the event specification by a `:'
  958. and a designator for the desired words. The words of an input line are
  959. numbered from 0, the first (usually command) word being 0, the second word
  960. (first argument) being 1, etc. The basic word designators are:
  961. .PP
  962. .PD 0
  963. .RS +4
  964. .TP 8
  965. 0
  966. The first (command) word
  967. .TP 8
  968. .I n
  969. The \fIn\fRth argument
  970. .TP 8
  971. ^
  972. The first argument, equivalent to `1'
  973. .TP 8
  974. $
  975. The last argument
  976. .TP 8
  977. %
  978. The word matched by an ?\fIs\fR? search
  979. .TP 8
  980. .I x\-y
  981. A range of words
  982. .TP 8
  983. .I \-y
  984. Equivalent to \fI`0\-y'\fR
  985. .TP 8
  986. *
  987. Equivalent to `^\-$', but returns nothing if the event contains only 1 word
  988. .TP 8
  989. .I x*
  990. Equivalent to \fI`x\-$'\fR
  991. .TP 8
  992. .I x\-
  993. Equivalent to \fI`x*'\fR, but omitting the last word (`$')
  994. .PD
  995. .RE
  996. .PP
  997. Selected words are inserted into the command line separated by single blanks.
  998. For example, the `diff' command in the previous example might have been
  999. typed as `diff !!:1.old !!:1' (using `:1' to select the first argument
  1000. from the previous event) or `diff !\-2:2 !\-2:1' to select and swap the
  1001. arguments from the `cp' command. If we didn't care about the order of the
  1002. `diff' we might have said `diff !\-2:1\-2' or simply `diff !\-2:*'.
  1003. The `cp' command might have been written `cp wumpus.man !#:1.old', using `#'
  1004. to refer to the current event.
  1005. `!n:\- hurkle.man' would reuse the first two words from the `nroff' command
  1006. to say `nroff \-man hurkle.man'.
  1007. .PP
  1008. The `:' separating the event specification from the word designator can be
  1009. omitted if the argument selector begins with a `^', `$', `*', `%' or `\-'.
  1010. For example, our `diff' command might have been `diff !!^.old !!^' or,
  1011. equivalently, `diff !!$.old !!$'. However, if `!!' is abbreviated `!',
  1012. an argument selector beginning with `\-' will be interpreted as an event
  1013. specification.
  1014. .PP
  1015. A history reference may have a word designator but no event specification.
  1016. It then references the previous command.
  1017. Continuing our `diff' example, we could have said simply `diff
  1018. !^.old !^' or, to get the arguments in the opposite order, just `diff !*'.
  1019. .PP
  1020. The word or words in a history reference can be edited, or ``modified'',
  1021. by following it with one or more modifiers, each preceded by a `:':
  1022. .PP
  1023. .PD 0
  1024. .RS +4
  1025. .TP 8
  1026. h
  1027. Remove a trailing pathname component, leaving the head.
  1028. .TP 8
  1029. t
  1030. Remove all leading pathname components, leaving the tail.
  1031. .TP 8
  1032. r
  1033. Remove a filename extension `.xxx', leaving the root name.
  1034. .TP 8
  1035. e
  1036. Remove all but the extension.
  1037. .TP 8
  1038. u
  1039. Uppercase the first lowercase letter.
  1040. .TP 8
  1041. l
  1042. Lowercase the first uppercase letter.
  1043. .TP 8
  1044. s\fI/l/r/\fR
  1045. Substitute \fIl\fR for \fIr\fR.
  1046. \fIl\fR is simply a string like \fIr\fR, not a regular expression as in
  1047. the eponymous \fIed\fR(1) command.
  1048. Any character may be used as the delimiter in place of `/';
  1049. a `\\' can be used to quote the delimiter inside \fIl\fR and \fIr\fR.
  1050. The character `&' in the \fIr\fR is replaced by \fIl\fR; `\\' also quotes `&'.
  1051. If \fIl\fR is empty (``''), the \fIl\fR from a previous substitution or the
  1052. \fIs\fR from a previous search or event number in event specification is used.
  1053. The trailing delimiter may be omitted if it is immediately followed by a newline.
  1054. .TP 8
  1055. &
  1056. Repeat the previous substitution.
  1057. .TP 8
  1058. g
  1059. Apply the following modifier once to each word.
  1060. .TP 8
  1061. a (+)
  1062. Apply the following modifier as many times as possible to a single word.
  1063. `a' and `g' can be used together to apply a modifier globally.
  1064. With the `s' modifier, only the patterns contained in the original word are
  1065. substituted, not patterns that contain any substitution result.
  1066. .TP 8
  1067. p
  1068. Print the new command line but do not execute it.
  1069. .TP 8
  1070. q
  1071. Quote the substituted words, preventing further substitutions.
  1072. .TP 8
  1073. x
  1074. Like q, but break into words at blanks, tabs and newlines.
  1075. .PD
  1076. .RE
  1077. .PP
  1078. Modifiers are applied to only the first modifiable word (unless `g' is used).
  1079. It is an error for no word to be modifiable.
  1080. .PP
  1081. For example, the `diff' command might have been written as `diff wumpus.man.old
  1082. !#^:r', using `:r' to remove `.old' from the first argument on the same line
  1083. (`!#^'). We could say `echo hello out there', then `echo !*:u' to capitalize
  1084. `hello', `echo !*:au' to say it out loud, or `echo !*:agu' to really shout.
  1085. We might follow `mail \-s "I forgot my password" rot' with `!:s/rot/root' to
  1086. correct the spelling of `root' (but see \fBSpelling correction\fR for a
  1087. different approach).
  1088. .PP
  1089. There is a special abbreviation for substitutions.
  1090. `^', when it is the first character on an input line, is equivalent to `!:s^'.
  1091. Thus we might have said `^rot^root' to make the spelling correction in the
  1092. previous example.
  1093. This is the only history substitution which does not explicitly begin with `!'.
  1094. .PP
  1095. (+) In \fIcsh\fR as such, only one modifier may be applied to each history
  1096. or variable expansion. In \fItcsh\fR, more than one may be used, for example
  1097. .IP "" 4
  1098. % mv wumpus.man /usr/man/man1/wumpus.1
  1099. .br
  1100. % man !$:t:r
  1101. .br
  1102. man wumpus
  1103. .PP
  1104. In \fIcsh\fR, the result would be `wumpus.1:r'. A substitution followed by a
  1105. colon may need to be insulated from it with braces:
  1106. .IP "" 4
  1107. > mv a.out /usr/games/wumpus
  1108. .br
  1109. > setenv PATH !$:h:$PATH
  1110. .br
  1111. Bad ! modifier: $.
  1112. .br
  1113. > setenv PATH !{\-2$:h}:$PATH
  1114. .br
  1115. setenv PATH /usr/games:/bin:/usr/bin:.
  1116. .PP
  1117. The first attempt would succeed in \fIcsh\fR but fails in \fItcsh\fR,
  1118. because \fItcsh\fR expects another modifier after the second colon
  1119. rather than `$'.
  1120. .PP
  1121. Finally, history can be accessed through the editor as well as through
  1122. the substitutions just described.
  1123. The \fIup-\fR and \fIdown-history\fR, \fIhistory-search-backward\fR and
  1124. \fI-forward\fR, \fIi-search-back\fR and \fI-fwd\fR,
  1125. \fIvi-search-back\fR and \fI-fwd\fR, \fIcopy-prev-word\fR
  1126. and \fIinsert-last-word\fR editor commands search for
  1127. events in the history list and copy them into the input buffer.
  1128. The \fItoggle-literal-history\fR editor command switches between the
  1129. expanded and literal forms of history lines in the input buffer.
  1130. \fIexpand-history\fR and \fIexpand-line\fR expand history substitutions
  1131. in the current word and in the entire input buffer respectively.
  1132. .SS "Alias substitution"
  1133. The shell maintains a list of aliases which can be set, unset and printed by
  1134. the \fIalias\fR and \fIunalias\fR commands. After a command line is parsed
  1135. into simple commands (see \fBCommands\fR) the first word of each command,
  1136. left-to-right, is checked to see if it has an alias. If so, the first word is
  1137. replaced by the alias. If the alias contains a history reference, it undergoes
  1138. \fBHistory substitution\fR (q.v.) as though the original command were the
  1139. previous input line. If the alias does not contain a history reference, the
  1140. argument list is left untouched.
  1141. .PP
  1142. Thus if the alias for `ls' were `ls \-l' the command `ls /usr' would become `ls
  1143. \-l /usr', the argument list here being undisturbed. If the alias for `lookup'
  1144. were `grep !^ /etc/passwd' then `lookup bill' would become `grep bill
  1145. /etc/passwd'. Aliases can be used to introduce parser metasyntax. For
  1146. example, `alias print 'pr \e!* | lpr'' defines a ``command'' (`print') which
  1147. \fIpr\fR(1)s its arguments to the line printer.
  1148. .PP
  1149. Alias substitution is repeated until the first word of the command has no
  1150. alias. If an alias substitution does not change the first word (as in the
  1151. previous example) it is flagged to prevent a loop. Other loops are detected and
  1152. cause an error.
  1153. .PP
  1154. Some aliases are referred to by the shell; see \fBSpecial aliases\fR.
  1155. .SS "Variable substitution"
  1156. The shell maintains a list of variables, each of which has as value a list of
  1157. zero or more words.
  1158. The values of shell variables can be displayed and changed with the
  1159. \fIset\fR and \fIunset\fR commands.
  1160. The system maintains its own list of ``environment'' variables.
  1161. These can be displayed and changed with \fIprintenv\fR, \fIsetenv\fR and
  1162. \fIunsetenv\fR.
  1163. .PP
  1164. (+) Variables may be made read-only with `set \-r' (q.v.).
  1165. Read-only variables may not be modified or unset;
  1166. attempting to do so will cause an error.
  1167. Once made read-only, a variable cannot be made writable,
  1168. so `set \-r' should be used with caution.
  1169. Environment variables cannot be made read-only.
  1170. .PP
  1171. Some variables are set by the shell or referred to by it.
  1172. For instance, the \fBargv\fR variable is an image of the shell's argument
  1173. list, and words of this variable's value are referred to in special ways.
  1174. Some of the variables referred to by the shell are toggles;
  1175. the shell does not care what their value is, only whether they are set or not.
  1176. For instance, the \fBverbose\fR variable is a toggle which causes command
  1177. input to be echoed. The \fB\-v\fR command line option sets