PageRenderTime 79ms CodeModel.GetById 29ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

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

Large files files are truncated, but you can click here to view the full file