/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
- .\" Copyright (c) 1980, 1990, 1993
- .\" The Regents of the University of California. All rights reserved.
- .\"
- .\" Redistribution and use in source and binary forms, with or without
- .\" modification, are permitted provided that the following conditions
- .\" are met:
- .\" 1. Redistributions of source code must retain the above copyright
- .\" notice, this list of conditions and the following disclaimer.
- .\" 2. Redistributions in binary form must reproduce the above copyright
- .\" notice, this list of conditions and the following disclaimer in the
- .\" documentation and/or other materials provided with the distribution.
- .\" 3. Neither the name of the University nor the names of its contributors
- .\" may be used to endorse or promote products derived from this software
- .\" without specific prior written permission.
- .\"
- .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- .\" SUCH DAMAGE.
- .\"
- .\" Style notes for the tcsh man page:
- .\"
- .\" - Tags in lists are bold, except in the FILES section where they are
- .\" italic.
- .\"
- .\" - References are bold for section headings and environment and shell
- .\" variables and italic for commands (externals, builtins, aliases, and
- .\" editor commands) and arguments to commands.
- .\"
- .\" - Be careful with the .B and .I macros: they handle only a limited number
- .\" of words. Work around this with \fB and \fI, but only if absolutely
- .\" necessary, because tcsh.man2html uses .B/.I to find name anchors.
- .\"
- .\" - Indent in multiples of 4, usually 8.
- .\"
- .\" - Use `', not '' or "", except of course in shell syntax examples.
- .\" '' at the beginning of a line will vanish!
- .\"
- .\" - Use \-, not -.
- .\"
- .\" - Include the tilde when naming dot files. `~/.login', not `.login'.
- .\"
- .\" - Refer to external commands in man page format, e.g., `csh(1)'. However,
- .\" tcsh is `tcsh', not `tcsh(1)', because this is the tcsh man page (and
- .\" see the next note anyway).
- .\"
- .\" - Say `the shell', not `tcsh', unless distinguishing between tcsh and csh.
- .\"
- .\" - Say `shell variable'/`environment variable' instead of `variable'
- .\" and `builtin command'/`editor command' instead of `builtin' or `command'
- .\" unless the distinction is absolutely clear from context.
- .\"
- .\" - Use the simple present tense. `The shell uses', not `The shell will use'.
- .\"
- .\" - IMPORTANT: Cross-reference as much as possible. Commands, variables,
- .\" etc. in the reference section should be mentioned in the appropriate
- .\" descriptive section, or at least in the reference-section description
- .\" of another command (or whatever) which is mentioned in a description
- .\" section. Remember to note OS-specific things in "OS variant support",
- .\" new features in NEW FEATURES and referenced external commands in SEE
- .\" ALSO.
- .\"
- .\" - tcsh.man2html depends heavily on the specific nroff commands used in the
- .\" man page when the script was written. Please stick closely to the style
- .\" used here if you can. In particular, please don't use nroff commands
- .\" which aren't already used herein.
- .\"
- .TH TCSH 1 "14 February 2012" "Astron 6.18.01"
- .SH NAME
- tcsh \- C shell with file name completion and command line editing
- .SH SYNOPSIS
- .B tcsh \fR[\fB\-bcdefFimnqstvVxX\fR] [\fB\-Dname\fR[\fB=value\fR]] [arg ...]
- .br
- .B tcsh \-l
- .SH DESCRIPTION
- \fItcsh\fR is an enhanced but completely compatible version of the Berkeley
- UNIX C shell, \fIcsh\fR(1).
- It is a command language interpreter usable both as an interactive login
- shell and a shell script command processor.
- It includes a command-line editor (see \fBThe command-line editor\fR),
- programmable word completion (see \fBCompletion and listing\fR),
- spelling correction (see \fBSpelling correction\fR),
- a history mechanism (see \fBHistory substitution\fR),
- job control (see \fBJobs\fR)
- and a C-like syntax.
- The \fBNEW FEATURES\fR section describes major enhancements of \fItcsh\fR
- over \fIcsh\fR(1).
- Throughout this manual, features of
- \fItcsh\fR not found in most \fIcsh\fR(1) implementations
- (specifically, the 4.4BSD \fIcsh\fR)
- are labeled with `(+)', and features which are present in \fIcsh\fR(1)
- but not usually documented are labeled with `(u)'.
- .SS "Argument list processing"
- If the first argument (argument 0) to the shell is `\-' then it is a
- login shell. A login shell can be also specified by invoking the shell with
- the \fB\-l\fR flag as the only argument.
- .PP
- The rest of the flag arguments are interpreted as follows:
- .TP 4
- .B \-b
- Forces a ``break'' from option processing, causing any
- further shell arguments to be treated as non-option arguments. The remaining
- arguments will not be interpreted as shell options. This may be used to pass
- options to a shell script without confusion or possible subterfuge. The shell
- will not run a set-user ID script without this option.
- .TP 4
- .B \-c
- Commands are read from the following argument (which must be present, and
- must be a single argument),
- stored in the \fBcommand\fR shell variable for reference, and executed.
- Any remaining arguments are placed in the \fBargv\fR shell variable.
- .TP 4
- .B \-d
- The shell loads the directory stack from \fI~/.cshdirs\fR as described under
- \fBStartup and shutdown\fR, whether or not it is a login shell. (+)
- .TP 4
- .B \-D\fIname\fR[=\fIvalue\fR]
- Sets the environment variable \fIname\fR to \fIvalue\fR. (Domain/OS only) (+)
- .TP 4
- .B \-e
- The shell exits if any invoked command terminates abnormally or
- yields a non-zero exit status.
- .TP 4
- .B \-f
- The shell does not load any resource or startup files, or perform any
- command hashing, and thus starts faster.
- .TP 4
- .B \-F
- The shell uses \fIfork\fR(2) instead of \fIvfork\fR(2) to spawn processes. (+)
- .TP 4
- .B \-i
- The shell is interactive and prompts for its top-level input, even if
- it appears to not be a terminal. Shells are interactive without this option if
- their inputs and outputs are terminals.
- .TP 4
- .B \-l
- The shell is a login shell. Applicable only if \fB\-l\fR is the only
- flag specified.
- .TP 4
- .B \-m
- The shell loads \fI~/.tcshrc\fR even if it does not belong to the effective
- user. Newer versions of \fIsu\fR(1) can pass \fB\-m\fR to the shell. (+)
- .TP 4
- .B \-n
- The shell parses commands but does not execute them.
- This aids in debugging shell scripts.
- .TP 4
- .B \-q
- The shell accepts SIGQUIT (see \fBSignal handling\fR) and behaves when
- it is used under a debugger. Job control is disabled. (u)
- .TP 4
- .B \-s
- Command input is taken from the standard input.
- .TP 4
- .B \-t
- The shell reads and executes a single line of input. A `\\' may be used to
- escape the newline at the end of this line and continue onto another line.
- .TP 4
- .B \-v
- Sets the \fBverbose\fR shell variable, so that
- command input is echoed after history substitution.
- .TP 4
- .B \-x
- Sets the \fBecho\fR shell variable, so that commands are echoed
- immediately before execution.
- .TP 4
- .B \-V
- Sets the \fBverbose\fR shell variable even before executing \fI~/.tcshrc\fR.
- .TP 4
- .B \-X
- Is to \fB\-x\fR as \fB\-V\fR is to \fB\-v\fR.
- .TP 4
- .B \-\-help
- Print a help message on the standard output and exit. (+)
- .TP 4
- .B \-\-version
- Print the version/platform/compilation options on the standard output and exit.
- This information is also contained in the \fBversion\fR shell variable. (+)
- .PP
- After processing of flag arguments, if arguments remain but none of the
- \fB\-c\fR, \fB\-i\fR, \fB\-s\fR, or \fB\-t\fR options were given, the first
- argument is taken as the name of a file of commands, or ``script'', to
- be executed. The shell opens this file and saves its name for possible
- resubstitution by `$0'. Because many systems use either the standard
- version 6 or version 7 shells whose shell scripts are not compatible
- with this shell, the shell uses such a `standard' shell to execute a script
- whose first character is not a `#', i.e., that does not start with a
- comment.
- .PP
- Remaining arguments are placed in the \fBargv\fR shell variable.
- .SS "Startup and shutdown"
- A login shell begins by executing commands from the system files
- \fI/etc/csh.cshrc\fR and \fI/etc/csh.login\fR.
- It then executes commands from files in the user's \fBhome\fR directory:
- first \fI~/.tcshrc\fR (+)
- or, if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR,
- then \fI~/.history\fR (or the value of the \fBhistfile\fR shell variable),
- then \fI~/.login\fR,
- and finally \fI~/.cshdirs\fR (or the value of the \fBdirsfile\fR shell variable) (+).
- The shell may read \fI/etc/csh.login\fR before instead of after
- \fI/etc/csh.cshrc\fR, and \fI~/.login\fR before instead of after
- \fI~/.tcshrc\fR or \fI~/.cshrc\fR and \fI~/.history\fR, if so compiled;
- see the \fBversion\fR shell variable. (+)
- .PP
- Non-login shells read only \fI/etc/csh.cshrc\fR and \fI~/.tcshrc\fR
- or \fI~/.cshrc\fR on startup.
- .PP
- For examples of startup files, please consult
- \fIhttp://tcshrc.sourceforge.net\fR.
- .PP
- Commands like \fIstty\fR(1) and \fItset\fR(1),
- which need be run only once per login, usually go in one's \fI~/.login\fR file.
- Users who need to use the same set of files with both \fIcsh\fR(1) and
- \fItcsh\fR can have only a \fI~/.cshrc\fR which checks for the existence of the
- \fBtcsh\fR shell variable (q.v.) before using \fItcsh\fR-specific commands,
- or can have both a \fI~/.cshrc\fR and a \fI~/.tcshrc\fR which \fIsource\fRs
- (see the builtin command) \fI~/.cshrc\fR.
- The rest of this manual uses `\fI~/.tcshrc\fR' to mean `\fI~/.tcshrc\fR or,
- if \fI~/.tcshrc\fR is not found, \fI~/.cshrc\fR'.
- .PP
- In the normal case, the shell begins reading commands from the terminal,
- prompting with `> '. (Processing of arguments and the use of the shell to
- process files containing command scripts are described later.)
- The shell repeatedly reads a line of command input, breaks it into words,
- places it on the command history list, parses it and executes each command
- in the line.
- .PP
- One can log out by typing `^D' on an empty line, `logout' or `login' or
- via the shell's autologout mechanism (see the \fBautologout\fR shell variable).
- When a login shell terminates it sets the \fBlogout\fR shell variable to
- `normal' or `automatic' as appropriate, then
- executes commands from the files
- \fI/etc/csh.logout\fR and \fI~/.logout\fR. The shell may drop DTR on logout
- if so compiled; see the \fBversion\fR shell variable.
- .PP
- The names of the system login and logout files vary from system to system for
- compatibility with different \fIcsh\fR(1) variants; see \fBFILES\fR.
- .SS Editing
- We first describe \fBThe command-line editor\fR.
- The \fBCompletion and listing\fR and \fBSpelling correction\fR sections
- describe two sets of functionality that are implemented as editor commands
- but which deserve their own treatment.
- Finally, \fBEditor commands\fR lists and describes
- the editor commands specific to the shell and their default bindings.
- .SS "The command-line editor (+)"
- Command-line input can be edited using key sequences much like those used in
- GNU Emacs or \fIvi\fR(1).
- The editor is active only when the \fBedit\fR shell variable is set, which
- it is by default in interactive shells.
- The \fIbindkey\fR builtin can display and change key bindings.
- Emacs-style key bindings are used by default
- (unless the shell was compiled otherwise; see the \fBversion\fR shell variable),
- but \fIbindkey\fR can change the key bindings to \fIvi\fR-style bindings en masse.
- .PP
- The shell always binds the arrow keys (as defined in the \fBTERMCAP\fR
- environment variable) to
- .PP
- .PD 0
- .RS +4
- .TP 8
- down
- \fIdown-history\fR
- .TP 8
- up
- \fIup-history\fR
- .TP 8
- left
- \fIbackward-char\fR
- .TP 8
- right
- \fIforward-char\fR
- .PD
- .RE
- .PP
- unless doing so would alter another single-character binding.
- One can set the arrow key escape sequences to the empty string with \fIsettc\fR
- to prevent these bindings.
- The ANSI/VT100 sequences for arrow keys are always bound.
- .PP
- Other key bindings are, for the most part, what Emacs and \fIvi\fR(1)
- users would expect and can easily be displayed by \fIbindkey\fR, so there
- is no need to list them here. Likewise, \fIbindkey\fR can list the editor
- commands with a short description of each.
- .PP
- Note that editor commands do not have the same notion of a ``word'' as does the
- shell. The editor delimits words with any non-alphanumeric characters not in
- the shell variable \fBwordchars\fR, while the shell recognizes only whitespace
- and some of the characters with special meanings to it, listed under
- \fBLexical structure\fR.
- .SS "Completion and listing (+)"
- The shell is often able to complete words when given a unique abbreviation.
- Type part of a word (for example `ls /usr/lost') and hit the tab key to
- run the \fIcomplete-word\fR editor command.
- The shell completes the filename `/usr/lost' to `/usr/lost+found/',
- replacing the incomplete word with the complete word in the input buffer.
- (Note the terminal `/'; completion adds a `/' to the
- end of completed directories and a space to the end of other completed words,
- to speed typing and provide a visual indicator of successful completion.
- The \fBaddsuffix\fR shell variable can be unset to prevent this.)
- If no match is found (perhaps `/usr/lost+found' doesn't exist),
- the terminal bell rings.
- If the word is already complete (perhaps there is a `/usr/lost' on your
- system, or perhaps you were thinking too far ahead and typed the whole thing)
- a `/' or space is added to the end if it isn't already there.
- .PP
- Completion works anywhere in the line, not at just the end; completed
- text pushes the rest of the line to the right. Completion in the middle of a word
- often results in leftover characters to the right of the cursor that need
- to be deleted.
- .PP
- Commands and variables can be completed in much the same way.
- For example, typing `em[tab]' would complete `em' to
- `emacs' if \fIemacs\fR were the only command on your system beginning with `em'.
- Completion can find a command in any directory in \fBpath\fR or if
- given a full pathname.
- Typing `echo $ar[tab]' would complete `$ar' to `$argv'
- if no other variable began with `ar'.
- .PP
- The shell parses the input buffer to determine whether the word you want to
- complete should be completed as a filename, command or variable.
- The first word in the buffer and the first word following
- `;', `|', `|&', `&&' or `||' is considered to be a command.
- A word beginning with `$' is considered to be a variable.
- Anything else is a filename. An empty line is `completed' as a filename.
- .PP
- You can list the possible completions of a word at any time by typing `^D'
- to run the \fIdelete-char-or-list-or-eof\fR editor command.
- The shell lists the possible completions using the \fIls\-F\fR builtin (q.v.)
- and reprints the prompt and unfinished command line, for example:
- .IP "" 4
- > ls /usr/l[^D]
- .br
- lbin/ lib/ local/ lost+found/
- .br
- > ls /usr/l
- .PP
- If the \fBautolist\fR shell variable is set, the shell lists the remaining
- choices (if any) whenever completion fails:
- .IP "" 4
- > set autolist
- .br
- > nm /usr/lib/libt[tab]
- .br
- libtermcap.a@ libtermlib.a@
- .br
- > nm /usr/lib/libterm
- .PP
- If \fBautolist\fR is set to `ambiguous', choices are listed only when
- completion fails and adds no new characters to the word being completed.
- .PP
- A filename to be completed can contain variables, your own or others' home
- directories abbreviated with `~' (see \fBFilename substitution\fR) and
- directory stack entries abbreviated with `='
- (see \fBDirectory stack substitution\fR). For example,
- .IP "" 4
- > ls ~k[^D]
- .br
- kahn kas kellogg
- .br
- > ls ~ke[tab]
- .br
- > ls ~kellogg/
- .PP
- or
- .IP "" 4
- > set local = /usr/local
- .br
- > ls $lo[tab]
- .br
- > ls $local/[^D]
- .br
- bin/ etc/ lib/ man/ src/
- .br
- > ls $local/
- .PP
- Note that variables can also be expanded explicitly with the
- \fIexpand-variables\fR editor command.
- .PP
- \fIdelete-char-or-list-or-eof\fR lists at only the end of the line;
- in the middle of a line it deletes the character under the cursor and
- on an empty line it logs one out or, if \fBignoreeof\fR is set, does nothing.
- `M-^D', bound to the editor command \fIlist-choices\fR, lists completion
- possibilities anywhere on a line, and \fIlist-choices\fR (or any one of the
- related editor commands that do or don't delete, list and/or log out,
- listed under \fIdelete-char-or-list-or-eof\fR) can be bound to `^D' with
- the \fIbindkey\fR builtin command if so desired.
- .PP
- The \fIcomplete-word-fwd\fR and \fIcomplete-word-back\fR editor commands
- (not bound to any keys by default) can be used to cycle up and down through
- the list of possible completions, replacing the current word with the next or
- previous word in the list.
- .PP
- The shell variable \fBfignore\fR can be set to a list of suffixes to be
- ignored by completion. Consider the following:
- .IP "" 4
- > ls
- .br
- Makefile condiments.h~ main.o side.c
- .br
- README main.c meal side.o
- .br
- condiments.h main.c~
- .br
- > set fignore = (.o \\~)
- .br
- > emacs ma[^D]
- .br
- main.c main.c~ main.o
- .br
- > emacs ma[tab]
- .br
- > emacs main.c
- .PP
- `main.c~' and `main.o' are ignored by completion (but not listing),
- because they end in suffixes in \fBfignore\fR.
- Note that a `\\' was needed in front of `~' to prevent it from being
- expanded to \fBhome\fR as described under \fBFilename substitution\fR.
- \fBfignore\fR is ignored if only one completion is possible.
- .PP
- If the \fBcomplete\fR shell variable is set to `enhance', completion
- 1) ignores case and 2) considers periods, hyphens and underscores
- (`.', `\-' and `_') to be word separators and hyphens and underscores to
- be equivalent. If you had the following files
- .IP "" 4
- comp.lang.c comp.lang.perl comp.std.c++
- .br
- comp.lang.c++ comp.std.c
- .PP
- and typed `mail \-f c.l.c[tab]', it would be completed to
- `mail \-f comp.lang.c', and ^D would list `comp.lang.c' and `comp.lang.c++'.
- `mail \-f c..c++[^D]' would list `comp.lang.c++' and `comp.std.c++'. Typing
- `rm a\-\-file[^D]' in the following directory
- .IP "" 4
- A_silly_file a-hyphenated-file another_silly_file
- .PP
- would list all three files, because case is ignored and hyphens and
- underscores are equivalent. Periods, however, are not equivalent to
- hyphens or underscores.
- .PP
- If the \fBcomplete\fR shell variable is set to `Enhance', completion
- ignores case and differences between a hyphen and an underscore word
- separator only when the user types a lowercase character or a hyphen.
- Entering an uppercase character or an underscore will not match the
- corresponding lowercase character or hyphen word separator.
- Typing `rm a\-\-file[^D]' in the directory of the previous example would
- still list all three files, but typing `rm A\-\-file' would match only
- `A_silly_file' and typing `rm a__file[^D]' would match just `A_silly_file'
- and `another_silly_file' because the user explicitly used an uppercase
- or an underscore character.
- .PP
- Completion and listing are affected by several other shell variables:
- \fBrecexact\fR can be set to complete on the shortest possible unique
- match, even if more typing might result in a longer match:
- .IP "" 4
- > ls
- .br
- fodder foo food foonly
- .br
- > set recexact
- .br
- > rm fo[tab]
- .PP
- just beeps, because `fo' could expand to `fod' or `foo', but if we type
- another `o',
- .IP "" 4
- > rm foo[tab]
- .br
- > rm foo
- .PP
- the completion completes on `foo', even though `food' and `foonly'
- also match.
- \fBautoexpand\fR can be set to run the \fIexpand-history\fR editor command
- before each completion attempt, \fBautocorrect\fR can be set to
- spelling-correct the word to be completed (see \fBSpelling correction\fR)
- before each completion attempt and \fBcorrect\fR can be set to complete
- commands automatically after one hits `return'.
- \fBmatchbeep\fR can be set to make completion beep or not beep in a variety
- of situations, and \fBnobeep\fR can be set to never beep at all.
- \fBnostat\fR can be set to a list of directories and/or patterns that
- match directories to prevent the completion mechanism from \fIstat\fR(2)ing
- those directories.
- \fBlistmax\fR and \fBlistmaxrows\fR can be set to limit the number of items
- and rows (respectively) that are listed without asking first.
- \fBrecognize_only_executables\fR can be set to make the shell list only
- executables when listing commands, but it is quite slow.
- .PP
- Finally, the \fIcomplete\fR builtin command can be used to tell the shell how
- to complete words other than filenames, commands and variables.
- Completion and listing do not work on glob-patterns (see \fBFilename substitution\fR),
- but the \fIlist-glob\fR and \fIexpand-glob\fR editor commands perform
- equivalent functions for glob-patterns.
- .SS "Spelling correction (+)"
- The shell can sometimes correct the spelling of filenames, commands and variable names
- as well as completing and listing them.
- .PP
- Individual words can be spelling-corrected with the \fIspell-word\fR
- editor command (usually bound to M-s and M-S)
- and the entire input buffer with \fIspell-line\fR (usually bound to M-$).
- The \fBcorrect\fR shell variable can be set to `cmd' to correct the
- command name or `all' to correct the entire line each time return is typed,
- and \fBautocorrect\fR can be set to correct the word to be completed
- before each completion attempt.
- .PP
- When spelling correction is invoked in any of these ways and
- the shell thinks that any part of the command line is misspelled,
- it prompts with the corrected line:
- .IP "" 4
- > set correct = cmd
- .br
- > lz /usr/bin
- .br
- CORRECT>ls /usr/bin (y|n|e|a)?
- .PP
- One can answer `y' or space to execute the corrected line,
- `e' to leave the uncorrected command in the input buffer,
- `a' to abort the command as if `^C' had been hit, and
- anything else to execute the original line unchanged.
- .PP
- Spelling correction recognizes user-defined completions (see the
- \fIcomplete\fR builtin command). If an input word in a position for
- which a completion is defined resembles a word in the completion list,
- spelling correction registers a misspelling and suggests the latter
- word as a correction. However, if the input word does not match any of
- the possible completions for that position, spelling correction does
- not register a misspelling.
- .PP
- Like completion, spelling correction works anywhere in the line,
- pushing the rest of the line to the right and possibly leaving
- extra characters to the right of the cursor.
- .PP
- Beware: spelling correction is not guaranteed to work the way one intends,
- and is provided mostly as an experimental feature.
- Suggestions and improvements are welcome.
- .SS "Editor commands (+)"
- `bindkey' lists key bindings and `bindkey \-l' lists and briefly describes
- editor commands.
- Only new or especially interesting editor commands are described here.
- See \fIemacs\fR(1) and \fIvi\fR(1) for descriptions of each editor's
- key bindings.
- .PP
- The character or characters to which each command is bound by default is
- given in parentheses. `^\fIcharacter\fR' means a control character and
- `M-\fIcharacter\fR' a meta character, typed as escape-\fIcharacter\fR
- on terminals without a meta key. Case counts, but commands that are bound
- to letters by default are bound to both lower- and uppercase letters for
- convenience.
- .TP 8
- .B complete-word \fR(tab)
- Completes a word as described under \fBCompletion and listing\fR.
- .TP 8
- .B complete-word-back \fR(not bound)
- Like \fIcomplete-word-fwd\fR, but steps up from the end of the list.
- .TP 8
- .B complete-word-fwd \fR(not bound)
- Replaces the current word with the first word in the list of possible
- completions. May be repeated to step down through the list.
- At the end of the list, beeps and reverts to the incomplete word.
- .TP 8
- .B complete-word-raw \fR(^X-tab)
- Like \fIcomplete-word\fR, but ignores user-defined completions.
- .TP 8
- .B copy-prev-word \fR(M-^_)
- Copies the previous word in the current line into the input buffer.
- See also \fIinsert-last-word\fR.
- .TP 8
- .B dabbrev-expand \fR(M-/)
- Expands the current word to the most recent preceding one for which
- the current is a leading substring, wrapping around the history list
- (once) if necessary.
- Repeating \fIdabbrev-expand\fR without any intervening typing
- changes to the next previous word etc., skipping identical matches
- much like \fIhistory-search-backward\fR does.
- .TP 8
- .B delete-char \fR(not bound)
- Deletes the character under the cursor.
- See also \fIdelete-char-or-list-or-eof\fR.
- .TP 8
- .B delete-char-or-eof \fR(not bound)
- Does \fIdelete-char\fR if there is a character under the cursor
- or \fIend-of-file\fR on an empty line.
- See also \fIdelete-char-or-list-or-eof\fR.
- .TP 8
- .B delete-char-or-list \fR(not bound)
- Does \fIdelete-char\fR if there is a character under the cursor
- or \fIlist-choices\fR at the end of the line.
- See also \fIdelete-char-or-list-or-eof\fR.
- .TP 8
- .B delete-char-or-list-or-eof \fR(^D)
- Does \fIdelete-char\fR if there is a character under the cursor,
- \fIlist-choices\fR at the end of the line
- or \fIend-of-file\fR on an empty line.
- See also those three commands, each of which does only a single action, and
- \fIdelete-char-or-eof\fR, \fIdelete-char-or-list\fR and \fIlist-or-eof\fR,
- each of which does a different two out of the three.
- .TP 8
- .B down-history \fR(down-arrow, ^N)
- Like \fIup-history\fR, but steps down, stopping at the original input line.
- .TP 8
- .B end-of-file \fR(not bound)
- Signals an end of file, causing the shell to exit unless the \fBignoreeof\fR
- shell variable (q.v.) is set to prevent this.
- See also \fIdelete-char-or-list-or-eof\fR.
- .TP 8
- .B expand-history \fR(M-space)
- Expands history substitutions in the current word.
- See \fBHistory substitution\fR.
- See also \fImagic-space\fR, \fItoggle-literal-history\fR and
- the \fBautoexpand\fR shell variable.
- .TP 8
- .B expand-glob \fR(^X-*)
- Expands the glob-pattern to the left of the cursor.
- See \fBFilename substitution\fR.
- .TP 8
- .B expand-line \fR(not bound)
- Like \fIexpand-history\fR, but
- expands history substitutions in each word in the input buffer.
- .TP 8
- .B expand-variables \fR(^X-$)
- Expands the variable to the left of the cursor.
- See \fBVariable substitution\fR.
- .TP 8
- .B history-search-backward \fR(M-p, M-P)
- Searches backwards through the history list for a command beginning with
- the current contents of the input buffer up to the cursor and copies it
- into the input buffer.
- The search string may be a glob-pattern (see \fBFilename substitution\fR)
- containing `*', `?', `[]' or `{}'.
- \fIup-history\fR and \fIdown-history\fR will proceed from the
- appropriate point in the history list.
- Emacs mode only.
- See also \fIhistory-search-forward\fR and \fIi-search-back\fR.
- .TP 8
- .B history-search-forward \fR(M-n, M-N)
- Like \fIhistory-search-backward\fR, but searches forward.
- .TP 8
- .B i-search-back \fR(not bound)
- Searches backward like \fIhistory-search-backward\fR, copies the first match
- into the input buffer with the cursor positioned at the end of the pattern,
- and prompts with `bck: ' and the first match. Additional characters may be
- typed to extend the search, \fIi-search-back\fR may be typed to continue
- searching with the same pattern, wrapping around the history list if
- necessary, (\fIi-search-back\fR must be bound to a
- single character for this to work) or one of the following special characters
- may be typed:
- .PP
- .RS +8
- .RS +4
- .PD 0
- .TP 8
- ^W
- Appends the rest of the word under the cursor to the search pattern.
- .TP 8
- delete (or any character bound to \fIbackward-delete-char\fR)
- Undoes the effect of the last character typed and deletes a character
- from the search pattern if appropriate.
- .TP 8
- ^G
- If the previous search was successful, aborts the entire search.
- If not, goes back to the last successful search.
- .TP 8
- escape
- Ends the search, leaving the current line in the input buffer.
- .RE
- .PD
- .PP
- Any other character not bound to \fIself-insert-command\fR terminates the
- search, leaving the current line in the input buffer, and
- is then interpreted as normal input. In particular, a carriage return
- causes the current line to be executed.
- Emacs mode only.
- See also \fIi-search-fwd\fR and \fIhistory-search-backward\fR.
- .RE
- .TP 8
- .B i-search-fwd \fR(not bound)
- Like \fIi-search-back\fR, but searches forward.
- .TP 8
- .B insert-last-word \fR(M-_)
- Inserts the last word of the previous input line (`!$') into the input buffer.
- See also \fIcopy-prev-word\fR.
- .TP 8
- .B list-choices \fR(M-^D)
- Lists completion possibilities as described under \fBCompletion and listing\fR.
- See also \fIdelete-char-or-list-or-eof\fR and \fIlist-choices-raw\fR.
- .TP 8
- .B list-choices-raw \fR(^X-^D)
- Like \fIlist-choices\fR, but ignores user-defined completions.
- .TP 8
- .B list-glob \fR(^X-g, ^X-G)
- Lists (via the \fIls\-F\fR builtin) matches to the glob-pattern
- (see \fBFilename substitution\fR) to the left of the cursor.
- .TP 8
- .B list-or-eof \fR(not bound)
- Does \fIlist-choices\fR
- or \fIend-of-file\fR on an empty line.
- See also \fIdelete-char-or-list-or-eof\fR.
- .TP 8
- .B magic-space \fR(not bound)
- Expands history substitutions in the current line,
- like \fIexpand-history\fR, and inserts a space.
- \fImagic-space\fR is designed to be bound to the space bar,
- but is not bound by default.
- .TP 8
- .B normalize-command \fR(^X-?)
- Searches for the current word in PATH and, if it is found, replaces it with
- the full path to the executable. Special characters are quoted. Aliases are
- expanded and quoted but commands within aliases are not. This command is
- useful with commands that take commands as arguments, e.g., `dbx' and `sh \-x'.
- .TP 8
- .B normalize-path \fR(^X-n, ^X-N)
- Expands the current word as described under the `expand' setting
- of the \fBsymlinks\fR shell variable.
- .TP 8
- .B overwrite-mode \fR(unbound)
- Toggles between input and overwrite modes.
- .TP 8
- .B run-fg-editor \fR(M-^Z)
- Saves the current input line and
- looks for a stopped job with a name equal to the last component of the
- file name part of the \fBEDITOR\fR or \fBVISUAL\fR environment variables,
- or, if neither is set, `ed' or `vi'.
- If such a job is found, it is restarted as if `fg %\fIjob\fR' had been
- typed. This is used to toggle back and forth between an editor and
- the shell easily. Some people bind this command to `^Z' so they
- can do this even more easily.
- .TP
- .B run-help \fR(M-h, M-H)
- Searches for documentation on the current command, using the same notion of
- `current command' as the completion routines, and prints it. There is no way
- to use a pager; \fIrun-help\fR is designed for short help files.
- If the special alias \fBhelpcommand\fR is defined, it is run with the
- command name as a sole argument. Else,
- documentation should be in a file named \fIcommand\fR.help, \fIcommand\fR.1,
- \fIcommand\fR.6, \fIcommand\fR.8 or \fIcommand\fR, which should be in one
- of the directories listed in the \fBHPATH\fR environment variable.
- If there is more than one help file only the first is printed.
- .TP 8
- .B self-insert-command \fR(text characters)
- In insert mode (the default), inserts the typed character into the input line after the character under the cursor.
- In overwrite mode, replaces the character under the cursor with the typed character.
- The input mode is normally preserved between lines, but the
- \fBinputmode\fR shell variable can be set to `insert' or `overwrite' to put the
- editor in that mode at the beginning of each line.
- See also \fIoverwrite-mode\fR.
- .TP 8
- .B sequence-lead-in \fR(arrow prefix, meta prefix, ^X)
- Indicates that the following characters are part of a
- multi-key sequence. Binding a command to a multi-key sequence really creates
- two bindings: the first character to \fIsequence-lead-in\fR and the
- whole sequence to the command. All sequences beginning with a character
- bound to \fIsequence-lead-in\fR are effectively bound to \fIundefined-key\fR
- unless bound to another command.
- .TP 8
- .B spell-line \fR(M-$)
- Attempts to correct the spelling of each word in the input buffer, like
- \fIspell-word\fR, but ignores words whose first character is one of
- `\-', `!', `^' or `%', or which contain `\\', `*' or `?', to avoid problems
- with switches, substitutions and the like.
- See \fBSpelling correction\fR.
- .TP 8
- .B spell-word \fR(M-s, M-S)
- Attempts to correct the spelling of the current word as described
- under \fBSpelling correction\fR.
- Checks each component of a word which appears to be a pathname.
- .TP 8
- .B toggle-literal-history \fR(M-r, M-R)
- Expands or `unexpands' history substitutions in the input buffer.
- See also \fIexpand-history\fR and the \fBautoexpand\fR shell variable.
- .TP 8
- .B undefined-key \fR(any unbound key)
- Beeps.
- .TP 8
- .B up-history \fR(up-arrow, ^P)
- Copies the previous entry in the history list into the input buffer.
- If \fBhistlit\fR is set, uses the literal form of the entry.
- May be repeated to step up through the history list, stopping at the top.
- .TP 8
- .B vi-search-back \fR(?)
- Prompts with `?' for a search string (which may be a glob-pattern, as with
- \fIhistory-search-backward\fR), searches for it and copies it into the
- input buffer. The bell rings if no match is found.
- Hitting return ends the search and leaves the last match in the input
- buffer.
- Hitting escape ends the search and executes the match.
- \fIvi\fR mode only.
- .TP 8
- .B vi-search-fwd \fR(/)
- Like \fIvi-search-back\fR, but searches forward.
- .TP 8
- .B which-command \fR(M-?)
- Does a \fIwhich\fR (see the description of the builtin command) on the
- first word of the input buffer.
- .TP 8
- .B yank-pop \fR(M-y)
- When executed immediately after a \fIyank\fR or another \fIyank-pop\fR,
- replaces the yanked string with the next previous string from the
- killring. This also has the effect of rotating the killring, such that
- this string will be considered the most recently killed by a later
- \fIyank\fR command. Repeating \fIyank-pop\fR will cycle through the
- killring any number of times.
- .SS "Lexical structure"
- The shell splits input lines into words at blanks and tabs. The special
- characters `&', `|', `;', `<', `>', `(', and `)' and the doubled characters
- `&&', `||', `<<' and `>>' are always separate words, whether or not they are
- surrounded by whitespace.
- .PP
- When the shell's input is not a terminal, the character `#' is taken to begin a
- comment. Each `#' and the rest of the input line on which it appears is
- discarded before further parsing.
- .PP
- A special character (including a blank or tab) may be prevented from having
- its special meaning, and possibly made part of another word, by preceding it
- with a backslash (`\\') or enclosing it in single (`''), double (`"') or
- backward (``') quotes. When not otherwise quoted a newline preceded by a `\\'
- is equivalent to a blank, but inside quotes this sequence results in a
- newline.
- .PP
- Furthermore, all \fBSubstitutions\fR (see below) except \fBHistory substitution\fR
- can be prevented by enclosing the strings (or parts of strings)
- in which they appear with single quotes or by quoting the crucial character(s)
- (e.g., `$' or ``' for \fBVariable substitution\fR or \fBCommand substitution\fR respectively)
- with `\\'. (\fBAlias substitution\fR is no exception: quoting in any way any
- character of a word for which an \fIalias\fR has been defined prevents
- substitution of the alias. The usual way of quoting an alias is to precede it
- with a backslash.) \fBHistory substitution\fR is prevented by
- backslashes but not by single quotes. Strings quoted with double or backward
- quotes undergo \fBVariable substitution\fR and \fBCommand substitution\fR, but other
- substitutions are prevented.
- .PP
- Text inside single or double quotes becomes a single word (or part of one).
- Metacharacters in these strings, including blanks and tabs, do not form
- separate words. Only in one special case (see \fBCommand substitution\fR
- below) can a double-quoted string yield parts of more than one word;
- single-quoted strings never do. Backward quotes are special: they signal
- \fBCommand substitution\fR (q.v.), which may result in more than one word.
- .PP
- Quoting complex strings, particularly strings which themselves contain quoting
- characters, can be confusing. Remember that quotes need not be used as they are
- in human writing! It may be easier to quote not an entire string, but only
- those parts of the string which need quoting, using different types of quoting
- to do so if appropriate.
- .PP
- The \fBbackslash_quote\fR shell variable (q.v.) can be set to make backslashes
- always quote `\\', `'', and `"'. (+) This may make complex quoting tasks
- easier, but it can cause syntax errors in \fIcsh\fR(1) scripts.
- .SS Substitutions
- We now describe the various transformations the shell performs on the input in
- the order in which they occur. We note in passing the data structures involved
- and the commands and variables which affect them. Remember that substitutions
- can be prevented by quoting as described under \fBLexical structure\fR.
- .SS "History substitution"
- Each command, or ``event'', input from the terminal is saved in the history
- list. The previous command is always saved, and the \fBhistory\fR shell
- variable can be set to a number to save that many commands. The \fBhistdup\fR
- shell variable can be set to not save duplicate events or consecutive duplicate
- events.
- .PP
- Saved commands are numbered sequentially from 1 and stamped with the time.
- It is not usually necessary to use event numbers, but the current event number
- can be made part of the prompt by placing an `!' in the \fBprompt\fR shell variable.
- .PP
- The shell actually saves history in expanded and literal (unexpanded) forms.
- If the \fBhistlit\fR shell variable is set, commands that display and store
- history use the literal form.
- .PP
- The \fIhistory\fR builtin command can print, store in a file, restore
- and clear the history list at any time,
- and the \fBsavehist\fR and \fBhistfile\fR shell variables can be set to
- store the history list automatically on logout and restore it on login.
- .PP
- History substitutions introduce words from the history list into the input
- stream, making it easy to repeat commands, repeat arguments of a previous
- command in the current command, or fix spelling mistakes in the previous
- command with little typing and a high degree of confidence.
- .PP
- History substitutions begin with the character `!'. They may begin anywhere in
- the input stream, but they do not nest. The `!' may be preceded by a `\\' to
- prevent its special meaning; for convenience, a `!' is passed unchanged when it
- is followed by a blank, tab, newline, `=' or `('. History substitutions also
- occur when an input line begins with `^'. This special abbreviation will be
- described later. The characters used to signal history substitution (`!' and
- `^') can be changed by setting the \fBhistchars\fR shell variable. Any input
- line which contains a history substitution is printed before it is executed.
- .PP
- A history substitution may have an ``event specification'', which indicates
- the event from which words are to be taken, a ``word designator'',
- which selects particular words from the chosen event, and/or a ``modifier'',
- which manipulates the selected words.
- .PP
- An event specification can be
- .PP
- .PD 0
- .RS +4
- .TP 8
- .I n
- A number, referring to a particular event
- .TP 8
- \-\fIn\fR
- An offset, referring to the event \fIn\fR before the current event
- .TP 8
- #
- The current event.
- This should be used carefully in \fIcsh\fR(1), where there is no check for
- recursion. \fItcsh\fR allows 10 levels of recursion. (+)
- .TP 8
- !
- The previous event (equivalent to `\-1')
- .TP 8
- .I s
- The most recent event whose first word begins with the string \fIs\fR
- .TP 8
- ?\fIs\fR?
- The most recent event which contains the string \fIs\fR.
- The second `?' can be omitted if it is immediately followed by a newline.
- .RE
- .PD
- .PP
- For example, consider this bit of someone's history list:
- .IP "" 4
- \ 9 8:30 nroff \-man wumpus.man
- .br
- 10 8:31 cp wumpus.man wumpus.man.old
- .br
- 11 8:36 vi wumpus.man
- .br
- 12 8:37 diff wumpus.man.old wumpus.man
- .PP
- The commands are shown with their event numbers and time stamps.
- The current event, which we haven't typed in yet, is event 13.
- `!11' and `!\-2' refer to event 11.
- `!!' refers to the previous event, 12. `!!' can be abbreviated `!' if it is
- followed by `:' (`:' is described below).
- `!n' refers to event 9, which begins with `n'.
- `!?old?' also refers to event 12, which contains `old'.
- Without word designators or modifiers history references simply expand to the
- entire event, so we might type `!cp' to redo the copy command or `!!|more'
- if the `diff' output scrolled off the top of the screen.
- .PP
- History references may be insulated from the surrounding text with braces if
- necessary. For example, `!vdoc' would look for a command beginning with
- `vdoc', and, in this example, not find one, but `!{v}doc' would expand
- unambiguously to `vi wumpus.mandoc'.
- Even in braces, history substitutions do not nest.
- .PP
- (+) While \fIcsh\fR(1) expands, for example, `!3d' to event 3 with the
- letter `d' appended to it, \fItcsh\fR expands it to the last event beginning
- with `3d'; only completely numeric arguments are treated as event numbers.
- This makes it possible to recall events beginning with numbers.
- To expand `!3d' as in \fIcsh\fR(1) say `!{3}d'.
- .PP
- To select words from an event we can follow the event specification by a `:'
- and a designator for the desired words. The words of an input line are
- numbered from 0, the first (usually command) word being 0, the second word
- (first argument) being 1, etc. The basic word designators are:
- .PP
- .PD 0
- .RS +4
- .TP 8
- 0
- The first (command) word
- .TP 8
- .I n
- The \fIn\fRth argument
- .TP 8
- ^
- The first argument, equivalent to `1'
- .TP 8
- $
- The last argument
- .TP 8
- %
- The word matched by an ?\fIs\fR? search
- .TP 8
- .I x\-y
- A range of words
- .TP 8
- .I \-y
- Equivalent to \fI`0\-y'\fR
- .TP 8
- *
- Equivalent to `^\-$', but returns nothing if the event contains only 1 word
- .TP 8
- .I x*
- Equivalent to \fI`x\-$'\fR
- .TP 8
- .I x\-
- Equivalent to \fI`x*'\fR, but omitting the last word (`$')
- .PD
- .RE
- .PP
- Selected words are inserted into the command line separated by single blanks.
- For example, the `diff' command in the previous example might have been
- typed as `diff !!:1.old !!:1' (using `:1' to select the first argument
- from the previous event) or `diff !\-2:2 !\-2:1' to select and swap the
- arguments from the `cp' command. If we didn't care about the order of the
- `diff' we might have said `diff !\-2:1\-2' or simply `diff !\-2:*'.
- The `cp' command might have been written `cp wumpus.man !#:1.old', using `#'
- to refer to the current event.
- `!n:\- hurkle.man' would reuse the first two words from the `nroff' command
- to say `nroff \-man hurkle.man'.
- .PP
- The `:' separating the event specification from the word designator can be
- omitted if the argument selector begins with a `^', `$', `*', `%' or `\-'.
- For example, our `diff' command might have been `diff !!^.old !!^' or,
- equivalently, `diff !!$.old !!$'. However, if `!!' is abbreviated `!',
- an argument selector beginning with `\-' will be interpreted as an event
- specification.
- .PP
- A history reference may have a word designator but no event specification.
- It then references the previous command.
- Continuing our `diff' example, we could have said simply `diff
- !^.old !^' or, to get the arguments in the opposite order, just `diff !*'.
- .PP
- The word or words in a history reference can be edited, or ``modified'',
- by following it with one or more modifiers, each preceded by a `:':
- .PP
- .PD 0
- .RS +4
- .TP 8
- h
- Remove a trailing pathname component, leaving the head.
- .TP 8
- t
- Remove all leading pathname components, leaving the tail.
- .TP 8
- r
- Remove a filename extension `.xxx', leaving the root name.
- .TP 8
- e
- Remove all but the extension.
- .TP 8
- u
- Uppercase the first lowercase letter.
- .TP 8
- l
- Lowercase the first uppercase letter.
- .TP 8
- s\fI/l/r/\fR
- Substitute \fIl\fR for \fIr\fR.
- \fIl\fR is simply a string like \fIr\fR, not a regular expression as in
- the eponymous \fIed\fR(1) command.
- Any character may be used as the delimiter in place of `/';
- a `\\' can be used to quote the delimiter inside \fIl\fR and \fIr\fR.
- The character `&' in the \fIr\fR is replaced by \fIl\fR; `\\' also quotes `&'.
- If \fIl\fR is empty (``''), the \fIl\fR from a previous substitution or the
- \fIs\fR from a previous search or event number in event specification is used.
- The trailing delimiter may be omitted if it is immediately followed by a newline.
- .TP 8
- &
- Repeat the previous substitution.
- .TP 8
- g
- Apply the following modifier once to each word.
- .TP 8
- a (+)
- Apply the following modifier as many times as possible to a single word.
- `a' and `g' can be used together to apply a modifier globally.
- With the `s' modifier, only the patterns contained in the original word are
- substituted, not patterns that contain any substitution result.
- .TP 8
- p
- Print the new command line but do not execute it.
- .TP 8
- q
- Quote the substituted words, preventing further substitutions.
- .TP 8
- x
- Like q, but break into words at blanks, tabs and newlines.
- .PD
- .RE
- .PP
- Modifiers are applied to only the first modifiable word (unless `g' is used).
- It is an error for no word to be modifiable.
- .PP
- For example, the `diff' command might have been written as `diff wumpus.man.old
- !#^:r', using `:r' to remove `.old' from the first argument on the same line
- (`!#^'). We could say `echo hello out there', then `echo !*:u' to capitalize
- `hello', `echo !*:au' to say it out loud, or `echo !*:agu' to really shout.
- We might follow `mail \-s "I forgot my password" rot' with `!:s/rot/root' to
- correct the spelling of `root' (but see \fBSpelling correction\fR for a
- different approach).
- .PP
- There is a special abbreviation for substitutions.
- `^', when it is the first character on an input line, is equivalent to `!:s^'.
- Thus we might have said `^rot^root' to make the spelling correction in the
- previous example.
- This is the only history substitution which does not explicitly begin with `!'.
- .PP
- (+) In \fIcsh\fR as such, only one modifier may be applied to each history
- or variable expansion. In \fItcsh\fR, more than one may be used, for example
- .IP "" 4
- % mv wumpus.man /usr/man/man1/wumpus.1
- .br
- % man !$:t:r
- .br
- man wumpus
- .PP
- In \fIcsh\fR, the result would be `wumpus.1:r'. A substitution followed by a
- colon may need to be insulated from it with braces:
- .IP "" 4
- > mv a.out /usr/games/wumpus
- .br
- > setenv PATH !$:h:$PATH
- .br
- Bad ! modifier: $.
- .br
- > setenv PATH !{\-2$:h}:$PATH
- .br
- setenv PATH /usr/games:/bin:/usr/bin:.
- .PP
- The first attempt would succeed in \fIcsh\fR but fails in \fItcsh\fR,
- because \fItcsh\fR expects another modifier after the second colon
- rather than `$'.
- .PP
- Finally, history can be accessed through the editor as well as through
- the substitutions just described.
- The \fIup-\fR and \fIdown-history\fR, \fIhistory-search-backward\fR and
- \fI-forward\fR, \fIi-search-back\fR and \fI-fwd\fR,
- \fIvi-search-back\fR and \fI-fwd\fR, \fIcopy-prev-word\fR
- and \fIinsert-last-word\fR editor commands search for
- events in the history list and copy them into the input buffer.
- The \fItoggle-literal-history\fR editor command switches between the
- expanded and literal forms of history lines in the input buffer.
- \fIexpand-history\fR and \fIexpand-line\fR expand history substitutions
- in the current word and in the entire input buffer respectively.
- .SS "Alias substitution"
- The shell maintains a list of aliases which can be set, unset and printed by
- the \fIalias\fR and \fIunalias\fR commands. After a command line is parsed
- into simple commands (see \fBCommands\fR) the first word of each command,
- left-to-right, is checked to see if it has an alias. If so, the first word is
- replaced by the alias. If the alias contains a history reference, it undergoes
- \fBHistory substitution\fR (q.v.) as though the original command were the
- previous input line. If the alias does not contain a history reference, the
- argument list is left untouched.
- .PP
- Thus if the alias for `ls' were `ls \-l' the command `ls /usr' would become `ls
- \-l /usr', the argument list here being undisturbed. If the alias for `lookup'
- were `grep !^ /etc/passwd' then `lookup bill' would become `grep bill
- /etc/passwd'. Aliases can be used to introduce parser metasyntax. For
- example, `alias print 'pr \e!* | lpr'' defines a ``command'' (`print') which
- \fIpr\fR(1)s its arguments to the line printer.
- .PP
- Alias substitution is repeated until the first word of the command has no
- alias. If an alias substitution does not change the first word (as in the
- previous example) it is flagged to prevent a loop. Other loops are detected and
- cause an error.
- .PP
- Some aliases are referred to by the shell; see \fBSpecial aliases\fR.
- .SS "Variable substitution"
- The shell maintains a list of variables, each of which has as value a list of
- zero or more words.
- The values of shell variables can be displayed and changed with the
- \fIset\fR and \fIunset\fR commands.
- The system maintains its own list of ``environment'' variables.
- These can be displayed and changed with \fIprintenv\fR, \fIsetenv\fR and
- \fIunsetenv\fR.
- .PP
- (+) Variables may be made read-only with `set \-r' (q.v.).
- Read-only variables may not be modified or unset;
- attempting to do so will cause an error.
- Once made read-only, a variable cannot be made writable,
- so `set \-r' should be used with caution.
- Environment variables cannot be made read-only.
- .PP
- Some variables are set by the shell or referred to by it.
- For instance, the \fBargv\fR variable is an image of the shell's argument
- list, and words of this variable's value are referred to in special ways.
- Some of the variables referred to by the shell are toggles;
- the shell does not care what their value is, only whether they are set or not.
- For instance, the \fBverbose\fR variable is a toggle which causes command
- input to be echoed. The \fB\-v\fR command line option sets…