[2460] | 1 | .\" $NetBSD: sh.1,v 1.80 2005/05/24 00:03:52 wiz Exp $
|
---|
| 2 | .\" Copyright (c) 1991, 1993
|
---|
| 3 | .\" The Regents of the University of California. All rights reserved.
|
---|
| 4 | .\"
|
---|
| 5 | .\" This code is derived from software contributed to Berkeley by
|
---|
| 6 | .\" Kenneth Almquist.
|
---|
| 7 | .\"
|
---|
| 8 | .\" Redistribution and use in source and binary forms, with or without
|
---|
| 9 | .\" modification, are permitted provided that the following conditions
|
---|
| 10 | .\" are met:
|
---|
| 11 | .\" 1. Redistributions of source code must retain the above copyright
|
---|
| 12 | .\" notice, this list of conditions and the following disclaimer.
|
---|
| 13 | .\" 2. Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | .\" notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | .\" documentation and/or other materials provided with the distribution.
|
---|
| 16 | .\" 3. Neither the name of the University nor the names of its contributors
|
---|
| 17 | .\" may be used to endorse or promote products derived from this software
|
---|
| 18 | .\" without specific prior written permission.
|
---|
| 19 | .\"
|
---|
| 20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
| 21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
| 22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
| 23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
| 24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
| 25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
| 26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
| 27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
| 28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
| 30 | .\" SUCH DAMAGE.
|
---|
| 31 | .\"
|
---|
| 32 | .\" @(#)sh.1 8.6 (Berkeley) 5/4/95
|
---|
| 33 | .\"
|
---|
| 34 | .Dd May 7, 2005
|
---|
| 35 | .Os
|
---|
| 36 | .Dt SH 1
|
---|
| 37 | .Sh NAME
|
---|
| 38 | .Nm sh
|
---|
| 39 | .Nd command interpreter (shell)
|
---|
| 40 | .Sh SYNOPSIS
|
---|
| 41 | .Nm
|
---|
| 42 | .Bk -words
|
---|
| 43 | .Op Fl aCefnuvxIimqVEb
|
---|
| 44 | .Op Cm +aCefnuvxIimqVEb
|
---|
| 45 | .Ek
|
---|
| 46 | .Bk -words
|
---|
| 47 | .Op Fl o Ar option_name
|
---|
| 48 | .Op Cm +o Ar option_name
|
---|
| 49 | .Ek
|
---|
| 50 | .Bk -words
|
---|
| 51 | .Op Ar command_file Oo Ar argument ... Oc
|
---|
| 52 | .Ek
|
---|
| 53 | .Nm
|
---|
| 54 | .Fl c
|
---|
| 55 | .Bk -words
|
---|
| 56 | .Op Fl aCefnuvxIimqVEb
|
---|
| 57 | .Op Cm +aCefnuvxIimqVEb
|
---|
| 58 | .Ek
|
---|
| 59 | .Bk -words
|
---|
| 60 | .Op Fl o Ar option_name
|
---|
| 61 | .Op Cm +o Ar option_name
|
---|
| 62 | .Ek
|
---|
| 63 | .Bk -words
|
---|
| 64 | .Ar command_string
|
---|
| 65 | .Op Ar command_name Oo Ar argument ... Oc
|
---|
| 66 | .Ek
|
---|
| 67 | .Nm
|
---|
| 68 | .Fl s
|
---|
| 69 | .Bk -words
|
---|
| 70 | .Op Fl aCefnuvxIimqVEb
|
---|
| 71 | .Op Cm +aCefnuvxIimqVEb
|
---|
| 72 | .Ek
|
---|
| 73 | .Bk -words
|
---|
| 74 | .Op Fl o Ar option_name
|
---|
| 75 | .Op Cm +o Ar option_name
|
---|
| 76 | .Ek
|
---|
| 77 | .Bk -words
|
---|
| 78 | .Op Ar argument ...
|
---|
| 79 | .Ek
|
---|
| 80 | .Sh DESCRIPTION
|
---|
| 81 | .Nm
|
---|
| 82 | is the standard command interpreter for the system.
|
---|
| 83 | The current version of
|
---|
| 84 | .Nm
|
---|
| 85 | is in the process of being changed to conform with the
|
---|
| 86 | .Tn POSIX
|
---|
| 87 | 1003.2 and 1003.2a specifications for the shell.
|
---|
| 88 | This version has many
|
---|
| 89 | features which make it appear similar in some respects to the Korn shell,
|
---|
| 90 | but it is not a Korn shell clone (see
|
---|
| 91 | .Xr ksh 1 ) .
|
---|
| 92 | Only features designated by
|
---|
| 93 | .Tn POSIX ,
|
---|
| 94 | plus a few Berkeley extensions, are being incorporated into this shell.
|
---|
| 95 | .\" We expect
|
---|
| 96 | .\" .Tn POSIX
|
---|
| 97 | .\" conformance by the time 4.4 BSD is released.
|
---|
| 98 | This man page is not intended
|
---|
| 99 | to be a tutorial or a complete specification of the shell.
|
---|
| 100 | .Ss Overview
|
---|
| 101 | The shell is a command that reads lines from either a file or the
|
---|
| 102 | terminal, interprets them, and generally executes other commands.
|
---|
| 103 | It is the program that is running when a user logs into the system
|
---|
| 104 | (although a user can select a different shell with the
|
---|
| 105 | .Xr chsh 1
|
---|
| 106 | command).
|
---|
| 107 | The shell implements a language that has flow control
|
---|
| 108 | constructs, a macro facility that provides a variety of features in
|
---|
| 109 | addition to data storage, along with built in history and line editing
|
---|
| 110 | capabilities.
|
---|
| 111 | It incorporates many features to aid interactive use and
|
---|
| 112 | has the advantage that the interpretative language is common to both
|
---|
| 113 | interactive and non-interactive use (shell scripts).
|
---|
| 114 | That is, commands
|
---|
| 115 | can be typed directly to the running shell or can be put into a file and
|
---|
| 116 | the file can be executed directly by the shell.
|
---|
| 117 | .Ss Invocation
|
---|
| 118 | If no args are present and if the standard input of the shell
|
---|
| 119 | is connected to a terminal (or if the
|
---|
| 120 | .Fl i
|
---|
| 121 | flag is set),
|
---|
| 122 | and the
|
---|
| 123 | .Fl c
|
---|
| 124 | option is not present, the shell is considered an interactive shell.
|
---|
| 125 | An interactive shell generally prompts before each command and handles
|
---|
| 126 | programming and command errors differently (as described below).
|
---|
| 127 | When first starting,
|
---|
| 128 | the shell inspects argument 0, and if it begins with a dash
|
---|
| 129 | .Sq - ,
|
---|
| 130 | the shell is also considered
|
---|
| 131 | a login shell.
|
---|
| 132 | This is normally done automatically by the system
|
---|
| 133 | when the user first logs in.
|
---|
| 134 | A login shell first reads commands
|
---|
| 135 | from the files
|
---|
| 136 | .Pa /etc/profile
|
---|
| 137 | and
|
---|
| 138 | .Pa .profile
|
---|
| 139 | if they exist.
|
---|
| 140 | If the environment variable
|
---|
| 141 | .Ev ENV
|
---|
| 142 | is set on entry to a shell, or is set in the
|
---|
| 143 | .Pa .profile
|
---|
| 144 | of a login shell, the shell next reads
|
---|
| 145 | commands from the file named in
|
---|
| 146 | .Ev ENV .
|
---|
| 147 | Therefore, a user should place commands that are to be executed only at
|
---|
| 148 | login time in the
|
---|
| 149 | .Pa .profile
|
---|
| 150 | file, and commands that are executed for every shell inside the
|
---|
| 151 | .Ev ENV
|
---|
| 152 | file.
|
---|
| 153 | To set the
|
---|
| 154 | .Ev ENV
|
---|
| 155 | variable to some file, place the following line in your
|
---|
| 156 | .Pa .profile
|
---|
| 157 | of your home directory
|
---|
| 158 | .Pp
|
---|
| 159 | .Dl ENV=$HOME/.shinit; export ENV
|
---|
| 160 | .Pp
|
---|
| 161 | substituting for
|
---|
| 162 | .Dq .shinit
|
---|
| 163 | any filename you wish.
|
---|
| 164 | Since the
|
---|
| 165 | .Ev ENV
|
---|
| 166 | file is read for every invocation of the shell, including shell scripts
|
---|
| 167 | and non-interactive shells, the following paradigm is useful for
|
---|
| 168 | restricting commands in the
|
---|
| 169 | .Ev ENV
|
---|
| 170 | file to interactive invocations.
|
---|
| 171 | Place commands within the
|
---|
| 172 | .Dq case
|
---|
| 173 | and
|
---|
| 174 | .Dq esac
|
---|
| 175 | below (these commands are described later):
|
---|
| 176 | .Pp
|
---|
| 177 | .Bl -item -compact -offset indent
|
---|
| 178 | .It
|
---|
| 179 | .Li case $- in *i*)
|
---|
| 180 | .Bl -item -compact -offset indent
|
---|
| 181 | .It
|
---|
| 182 | .Li # commands for interactive use only
|
---|
| 183 | .It
|
---|
| 184 | .Li ...
|
---|
| 185 | .El
|
---|
| 186 | .It
|
---|
| 187 | .Li esac
|
---|
| 188 | .El
|
---|
| 189 | .Pp
|
---|
| 190 | If command line arguments besides the options have been specified, then
|
---|
| 191 | the shell treats the first argument as the name of a file from which to
|
---|
| 192 | read commands (a shell script), and the remaining arguments are set as the
|
---|
| 193 | positional parameters of the shell ($1, $2, etc).
|
---|
| 194 | Otherwise, the shell
|
---|
| 195 | reads commands from its standard input.
|
---|
| 196 | .Ss Argument List Processing
|
---|
| 197 | All of the single letter options have a corresponding name that can be
|
---|
| 198 | used as an argument to the
|
---|
| 199 | .Fl o
|
---|
| 200 | option.
|
---|
| 201 | The set
|
---|
| 202 | .Fl o
|
---|
| 203 | name is provided next to the single letter option in
|
---|
| 204 | the description below.
|
---|
| 205 | Specifying a dash
|
---|
| 206 | .Dq -
|
---|
| 207 | turns the option on, while using a plus
|
---|
| 208 | .Dq +
|
---|
| 209 | disables the option.
|
---|
| 210 | The following options can be set from the command line or
|
---|
| 211 | with the
|
---|
| 212 | .Ic set
|
---|
| 213 | builtin (described later).
|
---|
| 214 | .Bl -tag -width aaaallexportfoo -offset indent
|
---|
| 215 | .It Fl a Em allexport
|
---|
| 216 | Export all variables assigned to.
|
---|
| 217 | .It Fl c
|
---|
| 218 | Read commands from the
|
---|
| 219 | .Ar command_string
|
---|
| 220 | operand instead of from the standard input.
|
---|
| 221 | Special parameter 0 will be set from the
|
---|
| 222 | .Ar command_name
|
---|
| 223 | operand and the positional parameters ($1, $2, etc.)
|
---|
| 224 | set from the remaining argument operands.
|
---|
| 225 | .It Fl C Em noclobber
|
---|
| 226 | Don't overwrite existing files with
|
---|
| 227 | .Dq \*[Gt] .
|
---|
| 228 | .It Fl e Em errexit
|
---|
| 229 | If not interactive, exit immediately if any untested command fails.
|
---|
| 230 | The exit status of a command is considered to be
|
---|
| 231 | explicitly tested if the command is used to control an
|
---|
| 232 | .Ic if ,
|
---|
| 233 | .Ic elif ,
|
---|
| 234 | .Ic while ,
|
---|
| 235 | or
|
---|
| 236 | .Ic until ;
|
---|
| 237 | or if the command is the left hand operand of an
|
---|
| 238 | .Dq \*[Am]\*[Am]
|
---|
| 239 | or
|
---|
| 240 | .Dq ||
|
---|
| 241 | operator.
|
---|
| 242 | .It Fl f Em noglob
|
---|
| 243 | Disable pathname expansion.
|
---|
| 244 | .It Fl n Em noexec
|
---|
| 245 | If not interactive, read commands but do not execute them.
|
---|
| 246 | This is useful for checking the syntax of shell scripts.
|
---|
| 247 | .It Fl u Em nounset
|
---|
| 248 | Write a message to standard error when attempting to expand a variable
|
---|
| 249 | that is not set, and if the shell is not interactive, exit immediately.
|
---|
| 250 | .It Fl v Em verbose
|
---|
| 251 | The shell writes its input to standard error as it is read.
|
---|
| 252 | Useful for debugging.
|
---|
| 253 | .It Fl x Em xtrace
|
---|
| 254 | Write each command to standard error (preceded by a
|
---|
| 255 | .Sq +\ )
|
---|
| 256 | before it is executed.
|
---|
| 257 | Useful for debugging.
|
---|
| 258 | .It Fl q Em quietprofile
|
---|
| 259 | If the
|
---|
| 260 | .Fl v
|
---|
| 261 | or
|
---|
| 262 | .Fl x
|
---|
| 263 | options have been set, do not apply them when reading
|
---|
| 264 | initialization files, these being
|
---|
| 265 | .Pa /etc/profile ,
|
---|
| 266 | .Pa .profile ,
|
---|
| 267 | and the file specified by the
|
---|
| 268 | .Ev ENV
|
---|
| 269 | environment variable.
|
---|
| 270 | .It Fl I Em ignoreeof
|
---|
| 271 | Ignore EOF's from input when interactive.
|
---|
| 272 | .It Fl i Em interactive
|
---|
| 273 | Force the shell to behave interactively.
|
---|
| 274 | .It Fl m Em monitor
|
---|
| 275 | Turn on job control (set automatically when interactive).
|
---|
| 276 | .It Fl s Em stdin
|
---|
| 277 | Read commands from standard input (set automatically if no file arguments
|
---|
| 278 | are present).
|
---|
| 279 | This option has no effect when set after the shell has
|
---|
| 280 | already started running (i.e. with
|
---|
| 281 | .Ic set ) .
|
---|
| 282 | .It Fl V Em vi
|
---|
| 283 | Enable the built-in
|
---|
| 284 | .Xr vi 1
|
---|
| 285 | command line editor (disables
|
---|
| 286 | .Fl E
|
---|
| 287 | if it has been set).
|
---|
| 288 | (See the
|
---|
| 289 | .Sx Command Line Editing
|
---|
| 290 | section below.)
|
---|
| 291 | .It Fl E Em emacs
|
---|
| 292 | Enable the built-in emacs style
|
---|
| 293 | command line editor (disables
|
---|
| 294 | .Fl V
|
---|
| 295 | if it has been set).
|
---|
| 296 | (See the
|
---|
| 297 | .Sx Command Line Editing
|
---|
| 298 | section below.)
|
---|
| 299 | .It Fl b Em notify
|
---|
| 300 | Enable asynchronous notification of background job completion.
|
---|
| 301 | (UNIMPLEMENTED for 4.4alpha)
|
---|
| 302 | .It "\ \ " Em cdprint
|
---|
| 303 | Make an interactive shell always print the new directory name when
|
---|
| 304 | changed by the
|
---|
| 305 | .Ic cd
|
---|
| 306 | command.
|
---|
| 307 | .It "\ \ " Em tabcomplete
|
---|
| 308 | Enables filename completion in the command line editor.
|
---|
| 309 | Typing a tab character will extend the current input word to match a
|
---|
| 310 | filename.
|
---|
| 311 | If more than one filename matches it is only extended to be the common prefix.
|
---|
| 312 | Typing a second tab character will list all the matching names.
|
---|
| 313 | .El
|
---|
| 314 | .Ss Lexical Structure
|
---|
| 315 | The shell reads input in terms of lines from a file and breaks it up into
|
---|
| 316 | words at whitespace (blanks and tabs), and at certain sequences of
|
---|
| 317 | characters that are special to the shell called
|
---|
| 318 | .Dq operators .
|
---|
| 319 | There are two types of operators: control operators and redirection
|
---|
| 320 | operators (their meaning is discussed later).
|
---|
| 321 | Following is a list of operators:
|
---|
| 322 | .Bl -ohang -offset indent
|
---|
| 323 | .It "Control operators:"
|
---|
| 324 | .Dl \*[Am] \*[Am]\*[Am] \&( \&) \&; ;; | || \*[Lt]newline\*[Gt]
|
---|
| 325 | .It "Redirection operators:"
|
---|
| 326 | .Dl \*[Lt] \*[Gt] \*[Gt]| \*[Lt]\*[Lt] \*[Gt]\*[Gt] \*[Lt]\*[Am] \*[Gt]\*[Am] \*[Lt]\*[Lt]- \*[Lt]\*[Gt]
|
---|
| 327 | .El
|
---|
| 328 | .Ss Quoting
|
---|
| 329 | Quoting is used to remove the special meaning of certain characters or
|
---|
| 330 | words to the shell, such as operators, whitespace, or keywords.
|
---|
| 331 | There are three types of quoting: matched single quotes,
|
---|
| 332 | matched double quotes, and backslash.
|
---|
| 333 | .Ss Backslash
|
---|
| 334 | A backslash preserves the literal meaning of the following
|
---|
| 335 | character, with the exception of
|
---|
| 336 | .Aq newline .
|
---|
| 337 | A backslash preceding a
|
---|
| 338 | .Aq newline
|
---|
| 339 | is treated as a line continuation.
|
---|
| 340 | .Ss Single Quotes
|
---|
| 341 | Enclosing characters in single quotes preserves the literal meaning of all
|
---|
| 342 | the characters (except single quotes, making it impossible to put
|
---|
| 343 | single-quotes in a single-quoted string).
|
---|
| 344 | .Ss Double Quotes
|
---|
| 345 | Enclosing characters within double quotes preserves the literal
|
---|
| 346 | meaning of all characters except dollarsign
|
---|
| 347 | .Pq $ ,
|
---|
| 348 | backquote
|
---|
| 349 | .Pq ` ,
|
---|
| 350 | and backslash
|
---|
| 351 | .Pq \e .
|
---|
| 352 | The backslash inside double quotes is historically weird, and serves to
|
---|
| 353 | quote only the following characters:
|
---|
| 354 | .Dl $ ` \*q \e \*[Lt]newline\*[Gt] .
|
---|
| 355 | Otherwise it remains literal.
|
---|
| 356 | .Ss Reserved Words
|
---|
| 357 | Reserved words are words that have special meaning to the
|
---|
| 358 | shell and are recognized at the beginning of a line and
|
---|
| 359 | after a control operator.
|
---|
| 360 | The following are reserved words:
|
---|
| 361 | .Bl -column while while while while while -offset indent
|
---|
| 362 | .It ! Ta elif Ta fi Ta while Ta case
|
---|
| 363 | .It else Ta for Ta then Ta { Ta }
|
---|
| 364 | .It do Ta done Ta until Ta if Ta esac
|
---|
| 365 | .El
|
---|
| 366 | .Pp
|
---|
| 367 | Their meaning is discussed later.
|
---|
| 368 | .Ss Aliases
|
---|
| 369 | An alias is a name and corresponding value set using the
|
---|
| 370 | .Ic alias
|
---|
| 371 | builtin command.
|
---|
| 372 | Whenever a reserved word may occur (see above),
|
---|
| 373 | and after checking for reserved words, the shell
|
---|
| 374 | checks the word to see if it matches an alias.
|
---|
| 375 | If it does, it replaces it in the input stream with its value.
|
---|
| 376 | For example, if there is an alias called
|
---|
| 377 | .Dq lf
|
---|
| 378 | with the value
|
---|
| 379 | .Dq "ls -F" ,
|
---|
| 380 | then the input:
|
---|
| 381 | .Pp
|
---|
| 382 | .Dl lf foobar Aq return
|
---|
| 383 | .Pp
|
---|
| 384 | would become
|
---|
| 385 | .Pp
|
---|
| 386 | .Dl ls -F foobar Aq return
|
---|
| 387 | .Pp
|
---|
| 388 | Aliases provide a convenient way for naive users to create shorthands for
|
---|
| 389 | commands without having to learn how to create functions with arguments.
|
---|
| 390 | They can also be used to create lexically obscure code.
|
---|
| 391 | This use is discouraged.
|
---|
| 392 | .Ss Commands
|
---|
| 393 | The shell interprets the words it reads according to a language, the
|
---|
| 394 | specification of which is outside the scope of this man page (refer to the
|
---|
| 395 | BNF in the
|
---|
| 396 | .Tn POSIX
|
---|
| 397 | 1003.2 document).
|
---|
| 398 | Essentially though, a line is read and if the first
|
---|
| 399 | word of the line (or after a control operator) is not a reserved word,
|
---|
| 400 | then the shell has recognized a simple command.
|
---|
| 401 | Otherwise, a complex
|
---|
| 402 | command or some other special construct may have been recognized.
|
---|
| 403 | .Ss Simple Commands
|
---|
| 404 | If a simple command has been recognized, the shell performs
|
---|
| 405 | the following actions:
|
---|
| 406 | .Bl -enum -offset indent
|
---|
| 407 | .It
|
---|
| 408 | Leading words of the form
|
---|
| 409 | .Dq name=value
|
---|
| 410 | are stripped off and assigned to the environment of the simple command.
|
---|
| 411 | Redirection operators and their arguments (as described below) are
|
---|
| 412 | stripped off and saved for processing.
|
---|
| 413 | .It
|
---|
| 414 | The remaining words are expanded as described in
|
---|
| 415 | the section called
|
---|
| 416 | .Dq Expansions ,
|
---|
| 417 | and the first remaining word is considered the command name and the
|
---|
| 418 | command is located.
|
---|
| 419 | The remaining words are considered the arguments of the command.
|
---|
| 420 | If no command name resulted, then the
|
---|
| 421 | .Dq name=value
|
---|
| 422 | variable assignments recognized in item 1 affect the current shell.
|
---|
| 423 | .It
|
---|
| 424 | Redirections are performed as described in the next section.
|
---|
| 425 | .El
|
---|
| 426 | .Ss Redirections
|
---|
| 427 | Redirections are used to change where a command reads its input or sends
|
---|
| 428 | its output.
|
---|
| 429 | In general, redirections open, close, or duplicate an
|
---|
| 430 | existing reference to a file.
|
---|
| 431 | The overall format used for redirection is:
|
---|
| 432 | .Pp
|
---|
| 433 | .Dl [n] Va redir-op Ar file
|
---|
| 434 | .Pp
|
---|
| 435 | where
|
---|
| 436 | .Va redir-op
|
---|
| 437 | is one of the redirection operators mentioned previously.
|
---|
| 438 | Following is a list of the possible redirections.
|
---|
| 439 | The
|
---|
| 440 | .Bq n
|
---|
| 441 | is an optional number, as in
|
---|
| 442 | .Sq 3
|
---|
| 443 | (not
|
---|
| 444 | .Sq Bq 3 ) ,
|
---|
| 445 | that refers to a file descriptor.
|
---|
| 446 | .Bl -tag -width aaabsfiles -offset indent
|
---|
| 447 | .It [n] Ns \*[Gt] file
|
---|
| 448 | Redirect standard output (or n) to file.
|
---|
| 449 | .It [n] Ns \*[Gt]| file
|
---|
| 450 | Same, but override the
|
---|
| 451 | .Fl C
|
---|
| 452 | option.
|
---|
| 453 | .It [n] Ns \*[Gt]\*[Gt] file
|
---|
| 454 | Append standard output (or n) to file.
|
---|
| 455 | .It [n] Ns \*[Lt] file
|
---|
| 456 | Redirect standard input (or n) from file.
|
---|
| 457 | .It [n1] Ns \*[Lt]\*[Am] Ns n2
|
---|
| 458 | Duplicate standard input (or n1) from file descriptor n2.
|
---|
| 459 | .It [n] Ns \*[Lt]\*[Am]-
|
---|
| 460 | Close standard input (or n).
|
---|
| 461 | .It [n1] Ns \*[Gt]\*[Am] Ns n2
|
---|
| 462 | Duplicate standard output (or n1) to n2.
|
---|
| 463 | .It [n] Ns \*[Gt]\*[Am]-
|
---|
| 464 | Close standard output (or n).
|
---|
| 465 | .It [n] Ns \*[Lt]\*[Gt] file
|
---|
| 466 | Open file for reading and writing on standard input (or n).
|
---|
| 467 | .El
|
---|
| 468 | .Pp
|
---|
| 469 | The following redirection is often called a
|
---|
| 470 | .Dq here-document .
|
---|
| 471 | .Bl -item -offset indent
|
---|
| 472 | .It
|
---|
| 473 | .Li [n]\*[Lt]\*[Lt] delimiter
|
---|
| 474 | .Dl here-doc-text ...
|
---|
| 475 | .Li delimiter
|
---|
| 476 | .El
|
---|
| 477 | .Pp
|
---|
| 478 | All the text on successive lines up to the delimiter is saved away and
|
---|
| 479 | made available to the command on standard input, or file descriptor n if
|
---|
| 480 | it is specified.
|
---|
| 481 | If the delimiter as specified on the initial line is
|
---|
| 482 | quoted, then the here-doc-text is treated literally, otherwise the text is
|
---|
| 483 | subjected to parameter expansion, command substitution, and arithmetic
|
---|
| 484 | expansion (as described in the section on
|
---|
| 485 | .Dq Expansions ) .
|
---|
| 486 | If the operator is
|
---|
| 487 | .Dq \*[Lt]\*[Lt]-
|
---|
| 488 | instead of
|
---|
| 489 | .Dq \*[Lt]\*[Lt] ,
|
---|
| 490 | then leading tabs in the here-doc-text are stripped.
|
---|
| 491 | .Ss Search and Execution
|
---|
| 492 | There are three types of commands: shell functions, builtin commands, and
|
---|
| 493 | normal programs -- and the command is searched for (by name) in that order.
|
---|
| 494 | They each are executed in a different way.
|
---|
| 495 | .Pp
|
---|
| 496 | When a shell function is executed, all of the shell positional parameters
|
---|
| 497 | (except $0, which remains unchanged) are set to the arguments of the shell
|
---|
| 498 | function.
|
---|
| 499 | The variables which are explicitly placed in the environment of
|
---|
| 500 | the command (by placing assignments to them before the function name) are
|
---|
| 501 | made local to the function and are set to the values given.
|
---|
| 502 | Then the command given in the function definition is executed.
|
---|
| 503 | The positional parameters are restored to their original values
|
---|
| 504 | when the command completes.
|
---|
| 505 | This all occurs within the current shell.
|
---|
| 506 | .Pp
|
---|
| 507 | Shell builtins are executed internally to the shell, without spawning a
|
---|
| 508 | new process.
|
---|
| 509 | .Pp
|
---|
| 510 | Otherwise, if the command name doesn't match a function or builtin, the
|
---|
| 511 | command is searched for as a normal program in the file system (as
|
---|
| 512 | described in the next section).
|
---|
| 513 | When a normal program is executed, the shell runs the program,
|
---|
| 514 | passing the arguments and the environment to the program.
|
---|
| 515 | If the program is not a normal executable file (i.e., if it does
|
---|
| 516 | not begin with the "magic number" whose
|
---|
| 517 | .Tn ASCII
|
---|
| 518 | representation is "#!", so
|
---|
| 519 | .Xr execve 2
|
---|
| 520 | returns
|
---|
| 521 | .Er ENOEXEC
|
---|
| 522 | then) the shell will interpret the program in a subshell.
|
---|
| 523 | The child shell will reinitialize itself in this case,
|
---|
| 524 | so that the effect will be as if a
|
---|
| 525 | new shell had been invoked to handle the ad-hoc shell script, except that
|
---|
| 526 | the location of hashed commands located in the parent shell will be
|
---|
| 527 | remembered by the child.
|
---|
| 528 | .Pp
|
---|
| 529 | Note that previous versions of this document and the source code itself
|
---|
| 530 | misleadingly and sporadically refer to a shell script without a magic
|
---|
| 531 | number as a "shell procedure".
|
---|
| 532 | .Ss Path Search
|
---|
| 533 | When locating a command, the shell first looks to see if it has a shell
|
---|
| 534 | function by that name.
|
---|
| 535 | Then it looks for a builtin command by that name.
|
---|
| 536 | If a builtin command is not found, one of two things happen:
|
---|
| 537 | .Bl -enum
|
---|
| 538 | .It
|
---|
| 539 | Command names containing a slash are simply executed without performing
|
---|
| 540 | any searches.
|
---|
| 541 | .It
|
---|
| 542 | The shell searches each entry in
|
---|
| 543 | .Ev PATH
|
---|
| 544 | in turn for the command.
|
---|
| 545 | The value of the
|
---|
| 546 | .Ev PATH
|
---|
| 547 | variable should be a series of entries separated by colons.
|
---|
| 548 | Each entry consists of a directory name.
|
---|
| 549 | The current directory may be indicated
|
---|
| 550 | implicitly by an empty directory name, or explicitly by a single period.
|
---|
| 551 | .El
|
---|
| 552 | .Ss Command Exit Status
|
---|
| 553 | Each command has an exit status that can influence the behavior
|
---|
| 554 | of other shell commands.
|
---|
| 555 | The paradigm is that a command exits
|
---|
| 556 | with zero for normal or success, and non-zero for failure,
|
---|
| 557 | error, or a false indication.
|
---|
| 558 | The man page for each command
|
---|
| 559 | should indicate the various exit codes and what they mean.
|
---|
| 560 | Additionally, the builtin commands return exit codes, as does
|
---|
| 561 | an executed shell function.
|
---|
| 562 | .Pp
|
---|
| 563 | If a command consists entirely of variable assignments then the
|
---|
| 564 | exit status of the command is that of the last command substitution
|
---|
| 565 | if any, otherwise 0.
|
---|
| 566 | .Ss Complex Commands
|
---|
| 567 | Complex commands are combinations of simple commands with control
|
---|
| 568 | operators or reserved words, together creating a larger complex command.
|
---|
| 569 | More generally, a command is one of the following:
|
---|
| 570 | .Bl -bullet
|
---|
| 571 | .It
|
---|
| 572 | simple command
|
---|
| 573 | .It
|
---|
| 574 | pipeline
|
---|
| 575 | .It
|
---|
| 576 | list or compound-list
|
---|
| 577 | .It
|
---|
| 578 | compound command
|
---|
| 579 | .It
|
---|
| 580 | function definition
|
---|
| 581 | .El
|
---|
| 582 | .Pp
|
---|
| 583 | Unless otherwise stated, the exit status of a command is that of the last
|
---|
| 584 | simple command executed by the command.
|
---|
| 585 | .Ss Pipelines
|
---|
| 586 | A pipeline is a sequence of one or more commands separated
|
---|
| 587 | by the control operator |.
|
---|
| 588 | The standard output of all but
|
---|
| 589 | the last command is connected to the standard input
|
---|
| 590 | of the next command.
|
---|
| 591 | The standard output of the last
|
---|
| 592 | command is inherited from the shell, as usual.
|
---|
| 593 | .Pp
|
---|
| 594 | The format for a pipeline is:
|
---|
| 595 | .Pp
|
---|
| 596 | .Dl [!] command1 [ | command2 ...]
|
---|
| 597 | .Pp
|
---|
| 598 | The standard output of command1 is connected to the standard input of
|
---|
| 599 | command2.
|
---|
| 600 | The standard input, standard output, or both of a command is
|
---|
| 601 | considered to be assigned by the pipeline before any redirection specified
|
---|
| 602 | by redirection operators that are part of the command.
|
---|
| 603 | .Pp
|
---|
| 604 | If the pipeline is not in the background (discussed later), the shell
|
---|
| 605 | waits for all commands to complete.
|
---|
| 606 | .Pp
|
---|
| 607 | If the reserved word ! does not precede the pipeline, the exit status is
|
---|
| 608 | the exit status of the last command specified in the pipeline.
|
---|
| 609 | Otherwise, the exit status is the logical NOT of the exit status of the
|
---|
| 610 | last command.
|
---|
| 611 | That is, if the last command returns zero, the exit status
|
---|
| 612 | is 1; if the last command returns greater than zero, the exit status is
|
---|
| 613 | zero.
|
---|
| 614 | .Pp
|
---|
| 615 | Because pipeline assignment of standard input or standard output or both
|
---|
| 616 | takes place before redirection, it can be modified by redirection.
|
---|
| 617 | For example:
|
---|
| 618 | .Pp
|
---|
| 619 | .Dl $ command1 2\*[Gt]\*[Am]1 | command2
|
---|
| 620 | .Pp
|
---|
| 621 | sends both the standard output and standard error of command1
|
---|
| 622 | to the standard input of command2.
|
---|
| 623 | .Pp
|
---|
| 624 | A ; or
|
---|
| 625 | .Aq newline
|
---|
| 626 | terminator causes the preceding AND-OR-list (described
|
---|
| 627 | next) to be executed sequentially; a \*[Am] causes asynchronous execution of
|
---|
| 628 | the preceding AND-OR-list.
|
---|
| 629 | .Pp
|
---|
| 630 | Note that unlike some other shells, each process in the pipeline is a
|
---|
| 631 | child of the invoking shell (unless it is a shell builtin, in which case
|
---|
| 632 | it executes in the current shell -- but any effect it has on the
|
---|
| 633 | environment is wiped).
|
---|
| 634 | .Ss Background Commands -- \*[Am]
|
---|
| 635 | If a command is terminated by the control operator ampersand (\*[Am]), the
|
---|
| 636 | shell executes the command asynchronously -- that is, the shell does not
|
---|
| 637 | wait for the command to finish before executing the next command.
|
---|
| 638 | .Pp
|
---|
| 639 | The format for running a command in background is:
|
---|
| 640 | .Pp
|
---|
| 641 | .Dl command1 \*[Am] [command2 \*[Am] ...]
|
---|
| 642 | .Pp
|
---|
| 643 | If the shell is not interactive, the standard input of an asynchronous
|
---|
| 644 | command is set to
|
---|
| 645 | .Pa /dev/null .
|
---|
| 646 | .Ss Lists -- Generally Speaking
|
---|
| 647 | A list is a sequence of zero or more commands separated by newlines,
|
---|
| 648 | semicolons, or ampersands, and optionally terminated by one of these three
|
---|
| 649 | characters.
|
---|
| 650 | The commands in a list are executed in the order they are written.
|
---|
| 651 | If command is followed by an ampersand, the shell starts the
|
---|
| 652 | command and immediately proceed onto the next command; otherwise it waits
|
---|
| 653 | for the command to terminate before proceeding to the next one.
|
---|
| 654 | .Ss Short-Circuit List Operators
|
---|
| 655 | .Dq \*[Am]\*[Am]
|
---|
| 656 | and
|
---|
| 657 | .Dq ||
|
---|
| 658 | are AND-OR list operators.
|
---|
| 659 | .Dq \*[Am]\*[Am]
|
---|
| 660 | executes the first command, and then executes the second command if and only
|
---|
| 661 | if the exit status of the first command is zero.
|
---|
| 662 | .Dq ||
|
---|
| 663 | is similar, but executes the second command if and only if the exit status
|
---|
| 664 | of the first command is nonzero.
|
---|
| 665 | .Dq \*[Am]\*[Am]
|
---|
| 666 | and
|
---|
| 667 | .Dq ||
|
---|
| 668 | both have the same priority.
|
---|
| 669 | Note that these operators are left-associative, so
|
---|
| 670 | .Dq true || echo bar && echo baz
|
---|
| 671 | writes
|
---|
| 672 | .Dq baz
|
---|
| 673 | and nothing else.
|
---|
| 674 | This is not the way it works in C.
|
---|
| 675 | .Ss Flow-Control Constructs -- if, while, for, case
|
---|
| 676 | The syntax of the if command is
|
---|
| 677 | .Bd -literal -offset indent
|
---|
| 678 | if list
|
---|
| 679 | then list
|
---|
| 680 | [ elif list
|
---|
| 681 | then list ] ...
|
---|
| 682 | [ else list ]
|
---|
| 683 | fi
|
---|
| 684 | .Ed
|
---|
| 685 | .Pp
|
---|
| 686 | The syntax of the while command is
|
---|
| 687 | .Bd -literal -offset indent
|
---|
| 688 | while list
|
---|
| 689 | do list
|
---|
| 690 | done
|
---|
| 691 | .Ed
|
---|
| 692 | .Pp
|
---|
| 693 | The two lists are executed repeatedly while the exit status of the
|
---|
| 694 | first list is zero.
|
---|
| 695 | The until command is similar, but has the word
|
---|
| 696 | until in place of while, which causes it to
|
---|
| 697 | repeat until the exit status of the first list is zero.
|
---|
| 698 | .Pp
|
---|
| 699 | The syntax of the for command is
|
---|
| 700 | .Bd -literal -offset indent
|
---|
| 701 | for variable in word ...
|
---|
| 702 | do list
|
---|
| 703 | done
|
---|
| 704 | .Ed
|
---|
| 705 | .Pp
|
---|
| 706 | The words are expanded, and then the list is executed repeatedly with the
|
---|
| 707 | variable set to each word in turn.
|
---|
| 708 | do and done may be replaced with
|
---|
| 709 | .Dq {
|
---|
| 710 | and
|
---|
| 711 | .Dq } .
|
---|
| 712 | .Pp
|
---|
| 713 | The syntax of the break and continue command is
|
---|
| 714 | .Bd -literal -offset indent
|
---|
| 715 | break [ num ]
|
---|
| 716 | continue [ num ]
|
---|
| 717 | .Ed
|
---|
| 718 | .Pp
|
---|
| 719 | Break terminates the num innermost for or while loops.
|
---|
| 720 | Continue continues with the next iteration of the innermost loop.
|
---|
| 721 | These are implemented as builtin commands.
|
---|
| 722 | .Pp
|
---|
| 723 | The syntax of the case command is
|
---|
| 724 | .Bd -literal -offset indent
|
---|
| 725 | case word in
|
---|
| 726 | pattern) list ;;
|
---|
| 727 | \&...
|
---|
| 728 | esac
|
---|
| 729 | .Ed
|
---|
| 730 | .Pp
|
---|
| 731 | The pattern can actually be one or more patterns (see
|
---|
| 732 | .Sx Shell Patterns
|
---|
| 733 | described later), separated by
|
---|
| 734 | .Dq \*(Ba
|
---|
| 735 | characters.
|
---|
| 736 | .Ss Grouping Commands Together
|
---|
| 737 | Commands may be grouped by writing either
|
---|
| 738 | .Pp
|
---|
| 739 | .Dl (list)
|
---|
| 740 | .Pp
|
---|
| 741 | or
|
---|
| 742 | .Pp
|
---|
| 743 | .Dl { list; }
|
---|
| 744 | .Pp
|
---|
| 745 | The first of these executes the commands in a subshell.
|
---|
| 746 | Builtin commands grouped into a (list) will not affect the current shell.
|
---|
| 747 | The second form does not fork another shell so is slightly more efficient.
|
---|
| 748 | Grouping commands together this way allows you to redirect
|
---|
| 749 | their output as though they were one program:
|
---|
| 750 | .Pp
|
---|
| 751 | .Bd -literal -offset indent
|
---|
| 752 | { echo -n \*q hello \*q ; echo \*q world" ; } \*[Gt] greeting
|
---|
| 753 | .Ed
|
---|
| 754 | .Pp
|
---|
| 755 | Note that
|
---|
| 756 | .Dq }
|
---|
| 757 | must follow a control operator (here,
|
---|
| 758 | .Dq \&; )
|
---|
| 759 | so that it is recognized as a reserved word and not as another command argument.
|
---|
| 760 | .Ss Functions
|
---|
| 761 | The syntax of a function definition is
|
---|
| 762 | .Pp
|
---|
| 763 | .Dl name ( ) command
|
---|
| 764 | .Pp
|
---|
| 765 | A function definition is an executable statement; when executed it
|
---|
| 766 | installs a function named name and returns an exit status of zero.
|
---|
| 767 | The command is normally a list enclosed between
|
---|
| 768 | .Dq {
|
---|
| 769 | and
|
---|
| 770 | .Dq } .
|
---|
| 771 | .Pp
|
---|
| 772 | Variables may be declared to be local to a function by using a local
|
---|
| 773 | command.
|
---|
| 774 | This should appear as the first statement of a function, and the syntax is
|
---|
| 775 | .Pp
|
---|
| 776 | .Dl local [ variable | - ] ...
|
---|
| 777 | .Pp
|
---|
| 778 | Local is implemented as a builtin command.
|
---|
| 779 | .Pp
|
---|
| 780 | When a variable is made local, it inherits the initial value and exported
|
---|
| 781 | and readonly flags from the variable with the same name in the surrounding
|
---|
| 782 | scope, if there is one.
|
---|
| 783 | Otherwise, the variable is initially unset.
|
---|
| 784 | The shell uses dynamic scoping, so that if you make the variable x local to
|
---|
| 785 | function f, which then calls function g, references to the variable x made
|
---|
| 786 | inside g will refer to the variable x declared inside f, not to the global
|
---|
| 787 | variable named x.
|
---|
| 788 | .Pp
|
---|
| 789 | The only special parameter that can be made local is
|
---|
| 790 | .Dq - .
|
---|
| 791 | Making
|
---|
| 792 | .Dq -
|
---|
| 793 | local any shell options that are changed via the set command inside the
|
---|
| 794 | function to be restored to their original values when the function
|
---|
| 795 | returns.
|
---|
| 796 | .Pp
|
---|
| 797 | The syntax of the return command is
|
---|
| 798 | .Pp
|
---|
| 799 | .Dl return [ exitstatus ]
|
---|
| 800 | .Pp
|
---|
| 801 | It terminates the currently executing function.
|
---|
| 802 | Return is implemented as a builtin command.
|
---|
| 803 | .Ss Variables and Parameters
|
---|
| 804 | The shell maintains a set of parameters.
|
---|
| 805 | A parameter denoted by a name is called a variable.
|
---|
| 806 | When starting up, the shell turns all the environment
|
---|
| 807 | variables into shell variables.
|
---|
| 808 | New variables can be set using the form
|
---|
| 809 | .Pp
|
---|
| 810 | .Dl name=value
|
---|
| 811 | .Pp
|
---|
| 812 | Variables set by the user must have a name consisting solely of
|
---|
| 813 | alphabetics, numerics, and underscores - the first of which must not be
|
---|
| 814 | numeric.
|
---|
| 815 | A parameter can also be denoted by a number or a special
|
---|
| 816 | character as explained below.
|
---|
| 817 | .Ss Positional Parameters
|
---|
| 818 | A positional parameter is a parameter denoted by a number (n \*[Gt] 0).
|
---|
| 819 | The shell sets these initially to the values of its command line arguments
|
---|
| 820 | that follow the name of the shell script.
|
---|
| 821 | The
|
---|
| 822 | .Ic set
|
---|
| 823 | builtin can also be used to set or reset them.
|
---|
| 824 | .Ss Special Parameters
|
---|
| 825 | A special parameter is a parameter denoted by one of the following special
|
---|
| 826 | characters.
|
---|
| 827 | The value of the parameter is listed next to its character.
|
---|
| 828 | .Bl -tag -width thinhyphena
|
---|
| 829 | .It *
|
---|
| 830 | Expands to the positional parameters, starting from one.
|
---|
| 831 | When the
|
---|
| 832 | expansion occurs within a double-quoted string it expands to a single
|
---|
| 833 | field with the value of each parameter separated by the first character of
|
---|
| 834 | the
|
---|
| 835 | .Ev IFS
|
---|
| 836 | variable, or by a
|
---|
| 837 | .Aq space
|
---|
| 838 | if
|
---|
| 839 | .Ev IFS
|
---|
| 840 | is unset.
|
---|
| 841 | .It @
|
---|
| 842 | Expands to the positional parameters, starting from one.
|
---|
| 843 | When the expansion occurs within double-quotes, each positional
|
---|
| 844 | parameter expands as a separate argument.
|
---|
| 845 | If there are no positional parameters, the
|
---|
| 846 | expansion of @ generates zero arguments, even when @ is
|
---|
| 847 | double-quoted.
|
---|
| 848 | What this basically means, for example, is
|
---|
| 849 | if $1 is
|
---|
| 850 | .Dq abc
|
---|
| 851 | and $2 is
|
---|
| 852 | .Dq def ghi ,
|
---|
| 853 | then
|
---|
| 854 | .Qq $@
|
---|
| 855 | expands to
|
---|
| 856 | the two arguments:
|
---|
| 857 | .Pp
|
---|
| 858 | .Sm off
|
---|
| 859 | .Dl \*q abc \*q \ \*q def\ ghi \*q
|
---|
| 860 | .Sm on
|
---|
| 861 | .It #
|
---|
| 862 | Expands to the number of positional parameters.
|
---|
| 863 | .It \&?
|
---|
| 864 | Expands to the exit status of the most recent pipeline.
|
---|
| 865 | .It - (Hyphen.)
|
---|
| 866 | Expands to the current option flags (the single-letter
|
---|
| 867 | option names concatenated into a string) as specified on
|
---|
| 868 | invocation, by the set builtin command, or implicitly
|
---|
| 869 | by the shell.
|
---|
| 870 | .It $
|
---|
| 871 | Expands to the process ID of the invoked shell.
|
---|
| 872 | A subshell retains the same value of $ as its parent.
|
---|
| 873 | .It \&!
|
---|
| 874 | Expands to the process ID of the most recent background
|
---|
| 875 | command executed from the current shell.
|
---|
| 876 | For a pipeline, the process ID is that of the last command in the pipeline.
|
---|
| 877 | .It 0 (Zero.)
|
---|
| 878 | Expands to the name of the shell or shell script.
|
---|
| 879 | .El
|
---|
| 880 | .Ss Word Expansions
|
---|
| 881 | This clause describes the various expansions that are performed on words.
|
---|
| 882 | Not all expansions are performed on every word, as explained later.
|
---|
| 883 | .Pp
|
---|
| 884 | Tilde expansions, parameter expansions, command substitutions, arithmetic
|
---|
| 885 | expansions, and quote removals that occur within a single word expand to a
|
---|
| 886 | single field.
|
---|
| 887 | It is only field splitting or pathname expansion that can
|
---|
| 888 | create multiple fields from a single word.
|
---|
| 889 | The single exception to this
|
---|
| 890 | rule is the expansion of the special parameter @ within double-quotes, as
|
---|
| 891 | was described above.
|
---|
| 892 | .Pp
|
---|
| 893 | The order of word expansion is:
|
---|
| 894 | .Bl -enum
|
---|
| 895 | .It
|
---|
| 896 | Tilde Expansion, Parameter Expansion, Command Substitution,
|
---|
| 897 | Arithmetic Expansion (these all occur at the same time).
|
---|
| 898 | .It
|
---|
| 899 | Field Splitting is performed on fields
|
---|
| 900 | generated by step (1) unless the
|
---|
| 901 | .Ev IFS
|
---|
| 902 | variable is null.
|
---|
| 903 | .It
|
---|
| 904 | Pathname Expansion (unless set
|
---|
| 905 | .Fl f
|
---|
| 906 | is in effect).
|
---|
| 907 | .It
|
---|
| 908 | Quote Removal.
|
---|
| 909 | .El
|
---|
| 910 | .Pp
|
---|
| 911 | The $ character is used to introduce parameter expansion, command
|
---|
| 912 | substitution, or arithmetic evaluation.
|
---|
| 913 | .Ss Tilde Expansion (substituting a user's home directory)
|
---|
| 914 | A word beginning with an unquoted tilde character (~) is
|
---|
| 915 | subjected to tilde expansion.
|
---|
| 916 | All the characters up to
|
---|
| 917 | a slash (/) or the end of the word are treated as a username
|
---|
| 918 | and are replaced with the user's home directory.
|
---|
| 919 | If the username is missing (as in
|
---|
| 920 | .Pa ~/foobar ) ,
|
---|
| 921 | the tilde is replaced with the value of the
|
---|
| 922 | .Va HOME
|
---|
| 923 | variable (the current user's home directory).
|
---|
| 924 | .Ss Parameter Expansion
|
---|
| 925 | The format for parameter expansion is as follows:
|
---|
| 926 | .Pp
|
---|
| 927 | .Dl ${expression}
|
---|
| 928 | .Pp
|
---|
| 929 | where expression consists of all characters until the matching
|
---|
| 930 | .Dq } .
|
---|
| 931 | Any
|
---|
| 932 | .Dq }
|
---|
| 933 | escaped by a backslash or within a quoted string, and characters in
|
---|
| 934 | embedded arithmetic expansions, command substitutions, and variable
|
---|
| 935 | expansions, are not examined in determining the matching
|
---|
| 936 | .Dq } .
|
---|
| 937 | .Pp
|
---|
| 938 | The simplest form for parameter expansion is:
|
---|
| 939 | .Pp
|
---|
| 940 | .Dl ${parameter}
|
---|
| 941 | .Pp
|
---|
| 942 | The value, if any, of parameter is substituted.
|
---|
| 943 | .Pp
|
---|
| 944 | The parameter name or symbol can be enclosed in braces, which are
|
---|
| 945 | optional except for positional parameters with more than one digit or
|
---|
| 946 | when parameter is followed by a character that could be interpreted as
|
---|
| 947 | part of the name.
|
---|
| 948 | If a parameter expansion occurs inside double-quotes:
|
---|
| 949 | .Bl -enum
|
---|
| 950 | .It
|
---|
| 951 | Pathname expansion is not performed on the results of the expansion.
|
---|
| 952 | .It
|
---|
| 953 | Field splitting is not performed on the results of the
|
---|
| 954 | expansion, with the exception of the special rules for @.
|
---|
| 955 | .El
|
---|
| 956 | .Pp
|
---|
| 957 | In addition, a parameter expansion can be modified by using one of the
|
---|
| 958 | following formats.
|
---|
| 959 | .Bl -tag -width aaparameterwordaaaaa
|
---|
| 960 | .It ${parameter:-word}
|
---|
| 961 | Use Default Values.
|
---|
| 962 | If parameter is unset or null, the expansion of word
|
---|
| 963 | is substituted; otherwise, the value of parameter is substituted.
|
---|
| 964 | .It ${parameter:=word}
|
---|
| 965 | Assign Default Values.
|
---|
| 966 | If parameter is unset or null, the expansion of
|
---|
| 967 | word is assigned to parameter.
|
---|
| 968 | In all cases, the final value of parameter is substituted.
|
---|
| 969 | Only variables, not positional parameters or special
|
---|
| 970 | parameters, can be assigned in this way.
|
---|
| 971 | .It ${parameter:?[word]}
|
---|
| 972 | Indicate Error if Null or Unset.
|
---|
| 973 | If parameter is unset or null, the
|
---|
| 974 | expansion of word (or a message indicating it is unset if word is omitted)
|
---|
| 975 | is written to standard error and the shell exits with a nonzero exit status.
|
---|
| 976 | Otherwise, the value of parameter is substituted.
|
---|
| 977 | An interactive shell need not exit.
|
---|
| 978 | .It ${parameter:+word}
|
---|
| 979 | Use Alternative Value.
|
---|
| 980 | If parameter is unset or null, null is
|
---|
| 981 | substituted; otherwise, the expansion of word is substituted.
|
---|
| 982 | .El
|
---|
| 983 | .Pp
|
---|
| 984 | In the parameter expansions shown previously, use of the colon in the
|
---|
| 985 | format results in a test for a parameter that is unset or null; omission
|
---|
| 986 | of the colon results in a test for a parameter that is only unset.
|
---|
| 987 | .Bl -tag -width aaparameterwordaaaaa
|
---|
| 988 | .It ${#parameter}
|
---|
| 989 | String Length.
|
---|
| 990 | The length in characters of the value of parameter.
|
---|
| 991 | .El
|
---|
| 992 | .Pp
|
---|
| 993 | The following four varieties of parameter expansion provide for substring
|
---|
| 994 | processing.
|
---|
| 995 | In each case, pattern matching notation (see
|
---|
| 996 | .Sx Shell Patterns ) ,
|
---|
| 997 | rather than regular expression notation, is used to evaluate the patterns.
|
---|
| 998 | If parameter is * or @, the result of the expansion is unspecified.
|
---|
| 999 | Enclosing the full parameter expansion string in double-quotes does not
|
---|
| 1000 | cause the following four varieties of pattern characters to be quoted,
|
---|
| 1001 | whereas quoting characters within the braces has this effect.
|
---|
| 1002 | .Bl -tag -width aaparameterwordaaaaa
|
---|
| 1003 | .It ${parameter%word}
|
---|
| 1004 | Remove Smallest Suffix Pattern.
|
---|
| 1005 | The word is expanded to produce a pattern.
|
---|
| 1006 | The parameter expansion then results in parameter, with the
|
---|
| 1007 | smallest portion of the suffix matched by the pattern deleted.
|
---|
| 1008 | .It ${parameter%%word}
|
---|
| 1009 | Remove Largest Suffix Pattern.
|
---|
| 1010 | The word is expanded to produce a pattern.
|
---|
| 1011 | The parameter expansion then results in parameter, with the largest
|
---|
| 1012 | portion of the suffix matched by the pattern deleted.
|
---|
| 1013 | .It ${parameter#word}
|
---|
| 1014 | Remove Smallest Prefix Pattern.
|
---|
| 1015 | The word is expanded to produce a pattern.
|
---|
| 1016 | The parameter expansion then results in parameter, with the
|
---|
| 1017 | smallest portion of the prefix matched by the pattern deleted.
|
---|
| 1018 | .It ${parameter##word}
|
---|
| 1019 | Remove Largest Prefix Pattern.
|
---|
| 1020 | The word is expanded to produce a pattern.
|
---|
| 1021 | The parameter expansion then results in parameter, with the largest
|
---|
| 1022 | portion of the prefix matched by the pattern deleted.
|
---|
| 1023 | .El
|
---|
| 1024 | .Ss Command Substitution
|
---|
| 1025 | Command substitution allows the output of a command to be substituted in
|
---|
| 1026 | place of the command name itself.
|
---|
| 1027 | Command substitution occurs when the command is enclosed as follows:
|
---|
| 1028 | .Pp
|
---|
| 1029 | .Dl $(command)
|
---|
| 1030 | .Pp
|
---|
| 1031 | or
|
---|
| 1032 | .Po
|
---|
| 1033 | .Dq backquoted
|
---|
| 1034 | version
|
---|
| 1035 | .Pc :
|
---|
| 1036 | .Pp
|
---|
| 1037 | .Dl `command`
|
---|
| 1038 | .Pp
|
---|
| 1039 | The shell expands the command substitution by executing command in a
|
---|
| 1040 | subshell environment and replacing the command substitution with the
|
---|
| 1041 | standard output of the command, removing sequences of one or more
|
---|
| 1042 | .Ao newline Ac Ns s
|
---|
| 1043 | at the end of the substitution.
|
---|
| 1044 | (Embedded
|
---|
| 1045 | .Ao newline Ac Ns s
|
---|
| 1046 | before
|
---|
| 1047 | the end of the output are not removed; however, during field splitting,
|
---|
| 1048 | they may be translated into
|
---|
| 1049 | .Ao space Ac Ns s ,
|
---|
| 1050 | depending on the value of
|
---|
| 1051 | .Ev IFS
|
---|
| 1052 | and quoting that is in effect.)
|
---|
| 1053 | .Ss Arithmetic Expansion
|
---|
| 1054 | Arithmetic expansion provides a mechanism for evaluating an arithmetic
|
---|
| 1055 | expression and substituting its value.
|
---|
| 1056 | The format for arithmetic expansion is as follows:
|
---|
| 1057 | .Pp
|
---|
| 1058 | .Dl $((expression))
|
---|
| 1059 | .Pp
|
---|
| 1060 | The expression is treated as if it were in double-quotes, except
|
---|
| 1061 | that a double-quote inside the expression is not treated specially.
|
---|
| 1062 | The shell expands all tokens in the expression for parameter expansion,
|
---|
| 1063 | command substitution, and quote removal.
|
---|
| 1064 | .Pp
|
---|
| 1065 | Next, the shell treats this as an arithmetic expression and
|
---|
| 1066 | substitutes the value of the expression.
|
---|
| 1067 | .Ss White Space Splitting (Field Splitting)
|
---|
| 1068 | After parameter expansion, command substitution, and
|
---|
| 1069 | arithmetic expansion the shell scans the results of
|
---|
| 1070 | expansions and substitutions that did not occur in double-quotes for
|
---|
| 1071 | field splitting and multiple fields can result.
|
---|
| 1072 | .Pp
|
---|
| 1073 | The shell treats each character of the
|
---|
| 1074 | .Ev IFS
|
---|
| 1075 | as a delimiter and use the delimiters to split the results of parameter
|
---|
| 1076 | expansion and command substitution into fields.
|
---|
| 1077 | .Pp
|
---|
| 1078 | Non-whitespace characters in
|
---|
| 1079 | .Ev IFS
|
---|
| 1080 | are treated strictly as parameter terminators.
|
---|
| 1081 | So adjacent non-whitespace
|
---|
| 1082 | .Ev IFS
|
---|
| 1083 | characters will produce empty parameters.
|
---|
| 1084 | .Pp
|
---|
| 1085 | If
|
---|
| 1086 | .Ev IFS
|
---|
| 1087 | is unset it is assumed to contain space, tab, and newline.
|
---|
| 1088 | .Ss Pathname Expansion (File Name Generation)
|
---|
| 1089 | Unless the
|
---|
| 1090 | .Fl f
|
---|
| 1091 | flag is set, file name generation is performed after word splitting is
|
---|
| 1092 | complete.
|
---|
| 1093 | Each word is viewed as a series of patterns, separated by slashes.
|
---|
| 1094 | The process of expansion replaces the word with the names of all
|
---|
| 1095 | existing files whose names can be formed by replacing each pattern with a
|
---|
| 1096 | string that matches the specified pattern.
|
---|
| 1097 | There are two restrictions on
|
---|
| 1098 | this: first, a pattern cannot match a string containing a slash, and
|
---|
| 1099 | second, a pattern cannot match a string starting with a period unless the
|
---|
| 1100 | first character of the pattern is a period.
|
---|
| 1101 | The next section describes the
|
---|
| 1102 | patterns used for both Pathname Expansion and the
|
---|
| 1103 | .Ic case
|
---|
| 1104 | command.
|
---|
| 1105 | .Ss Shell Patterns
|
---|
| 1106 | A pattern consists of normal characters, which match themselves,
|
---|
| 1107 | and meta-characters.
|
---|
| 1108 | The meta-characters are
|
---|
| 1109 | .Dq \&! ,
|
---|
| 1110 | .Dq * ,
|
---|
| 1111 | .Dq \&? ,
|
---|
| 1112 | and
|
---|
| 1113 | .Dq \&[ .
|
---|
| 1114 | These characters lose their special meanings if they are quoted.
|
---|
| 1115 | When command or variable substitution is performed
|
---|
| 1116 | and the dollar sign or back quotes are not double quoted,
|
---|
| 1117 | the value of the variable or the output of
|
---|
| 1118 | the command is scanned for these characters and they are turned into
|
---|
| 1119 | meta-characters.
|
---|
| 1120 | .Pp
|
---|
| 1121 | An asterisk
|
---|
| 1122 | .Pq Dq *
|
---|
| 1123 | matches any string of characters.
|
---|
| 1124 | A question mark matches any single character.
|
---|
| 1125 | A left bracket
|
---|
| 1126 | .Pq Dq \&[
|
---|
| 1127 | introduces a character class.
|
---|
| 1128 | The end of the character class is indicated by a
|
---|
| 1129 | .Pq Dq \&] ;
|
---|
| 1130 | if the
|
---|
| 1131 | .Dq \&]
|
---|
| 1132 | is missing then the
|
---|
| 1133 | .Dq \&[
|
---|
| 1134 | matches a
|
---|
| 1135 | .Dq \&[
|
---|
| 1136 | rather than introducing a character class.
|
---|
| 1137 | A character class matches any of the characters between the square brackets.
|
---|
| 1138 | A range of characters may be specified using a minus sign.
|
---|
| 1139 | The character class may be complemented
|
---|
| 1140 | by making an exclamation point the first character of the character class.
|
---|
| 1141 | .Pp
|
---|
| 1142 | To include a
|
---|
| 1143 | .Dq \&]
|
---|
| 1144 | in a character class, make it the first character listed (after the
|
---|
| 1145 | .Dq \&! ,
|
---|
| 1146 | if any).
|
---|
| 1147 | To include a minus sign, make it the first or last character listed.
|
---|
| 1148 | .Ss Builtins
|
---|
| 1149 | This section lists the builtin commands which are builtin because they
|
---|
| 1150 | need to perform some operation that can't be performed by a separate
|
---|
| 1151 | process.
|
---|
| 1152 | In addition to these, there are several other commands that may
|
---|
| 1153 | be builtin for efficiency (e.g.
|
---|
| 1154 | .Xr printf 1 ,
|
---|
| 1155 | .Xr echo 1 ,
|
---|
| 1156 | .Xr test 1 ,
|
---|
| 1157 | etc).
|
---|
| 1158 | .Bl -tag -width 5n
|
---|
| 1159 | .It :
|
---|
| 1160 | A null command that returns a 0 (true) exit value.
|
---|
| 1161 | .It \&. file
|
---|
| 1162 | The commands in the specified file are read and executed by the shell.
|
---|
| 1163 | .It alias Op Ar name Ns Op Ar "=string ..."
|
---|
| 1164 | If
|
---|
| 1165 | .Ar name=string
|
---|
| 1166 | is specified, the shell defines the alias
|
---|
| 1167 | .Ar name
|
---|
| 1168 | with value
|
---|
| 1169 | .Ar string .
|
---|
| 1170 | If just
|
---|
| 1171 | .Ar name
|
---|
| 1172 | is specified, the value of the alias
|
---|
| 1173 | .Ar name
|
---|
| 1174 | is printed.
|
---|
| 1175 | With no arguments, the
|
---|
| 1176 | .Ic alias
|
---|
| 1177 | builtin prints the
|
---|
| 1178 | names and values of all defined aliases (see
|
---|
| 1179 | .Ic unalias ) .
|
---|
| 1180 | .It bg [ Ar job ] ...
|
---|
| 1181 | Continue the specified jobs (or the current job if no
|
---|
| 1182 | jobs are given) in the background.
|
---|
| 1183 | .It Xo command
|
---|
| 1184 | .Op Fl p
|
---|
| 1185 | .Op Fl v
|
---|
| 1186 | .Op Fl V
|
---|
| 1187 | .Ar command
|
---|
| 1188 | .Op Ar arg ...
|
---|
| 1189 | .Xc
|
---|
| 1190 | Execute the specified command but ignore shell functions when searching
|
---|
| 1191 | for it.
|
---|
| 1192 | (This is useful when you
|
---|
| 1193 | have a shell function with the same name as a builtin command.)
|
---|
| 1194 | .Bl -tag -width 5n
|
---|
| 1195 | .It Fl p
|
---|
| 1196 | search for command using a
|
---|
| 1197 | .Ev PATH
|
---|
| 1198 | that guarantees to find all the standard utilities.
|
---|
| 1199 | .It Fl V
|
---|
| 1200 | Do not execute the command but
|
---|
| 1201 | search for the command and print the resolution of the
|
---|
| 1202 | command search.
|
---|
| 1203 | This is the same as the type builtin.
|
---|
| 1204 | .It Fl v
|
---|
| 1205 | Do not execute the command but
|
---|
| 1206 | search for the command and print the absolute pathname
|
---|
| 1207 | of utilities, the name for builtins or the expansion of aliases.
|
---|
| 1208 | .El
|
---|
| 1209 | .It cd Op Ar directory Op Ar replace
|
---|
| 1210 | Switch to the specified directory (default
|
---|
| 1211 | .Ev $HOME ) .
|
---|
| 1212 | If
|
---|
| 1213 | .Ar replace
|
---|
| 1214 | is specified, then the new directory name is generated by replacing
|
---|
| 1215 | the first occurrence of
|
---|
| 1216 | .Ar directory
|
---|
| 1217 | in the current directory name with
|
---|
| 1218 | .Ar replace .
|
---|
| 1219 | Otherwise if an entry for
|
---|
| 1220 | .Ev CDPATH
|
---|
| 1221 | appears in the environment of the
|
---|
| 1222 | .Ic cd
|
---|
| 1223 | command or the shell variable
|
---|
| 1224 | .Ev CDPATH
|
---|
| 1225 | is set and the directory name does not begin with a slash, then the
|
---|
| 1226 | directories listed in
|
---|
| 1227 | .Ev CDPATH
|
---|
| 1228 | will be searched for the specified directory.
|
---|
| 1229 | The format of
|
---|
| 1230 | .Ev CDPATH
|
---|
| 1231 | is the same as that of
|
---|
| 1232 | .Ev PATH .
|
---|
| 1233 | In an interactive shell, the
|
---|
| 1234 | .Ic cd
|
---|
| 1235 | command will print out the name of the
|
---|
| 1236 | directory that it actually switched to if this is different from the name
|
---|
| 1237 | that the user gave.
|
---|
| 1238 | These may be different either because the
|
---|
| 1239 | .Ev CDPATH
|
---|
| 1240 | mechanism was used or because a symbolic link was crossed.
|
---|
| 1241 | .It eval Ar string ...
|
---|
| 1242 | Concatenate all the arguments with spaces.
|
---|
| 1243 | Then re-parse and execute the command.
|
---|
| 1244 | .It exec Op Ar command arg ...
|
---|
| 1245 | Unless command is omitted, the shell process is replaced with the
|
---|
| 1246 | specified program (which must be a real program, not a shell builtin or
|
---|
| 1247 | function).
|
---|
| 1248 | Any redirections on the
|
---|
| 1249 | .Ic exec
|
---|
| 1250 | command are marked as permanent, so that they are not undone when the
|
---|
| 1251 | .Ic exec
|
---|
| 1252 | command finishes.
|
---|
| 1253 | .It exit Op Ar exitstatus
|
---|
| 1254 | Terminate the shell process.
|
---|
| 1255 | If
|
---|
| 1256 | .Ar exitstatus
|
---|
| 1257 | is given it is used as the exit status of the shell; otherwise the
|
---|
| 1258 | exit status of the preceding command is used.
|
---|
| 1259 | .It export Ar name ...
|
---|
| 1260 | .It export Fl p
|
---|
| 1261 | The specified names are exported so that they will appear in the
|
---|
| 1262 | environment of subsequent commands.
|
---|
| 1263 | The only way to un-export a variable is to unset it.
|
---|
| 1264 | The shell allows the value of a variable to be set at the
|
---|
| 1265 | same time it is exported by writing
|
---|
| 1266 | .Pp
|
---|
| 1267 | .Dl export name=value
|
---|
| 1268 | .Pp
|
---|
| 1269 | With no arguments the export command lists the names of all exported variables.
|
---|
| 1270 | With the
|
---|
| 1271 | .Fl p
|
---|
| 1272 | option specified the output will be formatted suitably for non-interactive use.
|
---|
| 1273 | .It Xo fc Op Fl e Ar editor
|
---|
| 1274 | .Op Ar first Op Ar last
|
---|
| 1275 | .Xc
|
---|
| 1276 | .It Xo fc Fl l
|
---|
| 1277 | .Op Fl nr
|
---|
| 1278 | .Op Ar first Op Ar last
|
---|
| 1279 | .Xc
|
---|
| 1280 | .It Xo fc Fl s Op Ar old=new
|
---|
| 1281 | .Op Ar first
|
---|
| 1282 | .Xc
|
---|
| 1283 | The
|
---|
| 1284 | .Ic fc
|
---|
| 1285 | builtin lists, or edits and re-executes, commands previously entered
|
---|
| 1286 | to an interactive shell.
|
---|
| 1287 | .Bl -tag -width 5n
|
---|
| 1288 | .It Fl e No editor
|
---|
| 1289 | Use the editor named by editor to edit the commands.
|
---|
| 1290 | The editor string is a command name, subject to search via the
|
---|
| 1291 | .Ev PATH
|
---|
| 1292 | variable.
|
---|
| 1293 | The value in the
|
---|
| 1294 | .Ev FCEDIT
|
---|
| 1295 | variable is used as a default when
|
---|
| 1296 | .Fl e
|
---|
| 1297 | is not specified.
|
---|
| 1298 | If
|
---|
| 1299 | .Ev FCEDIT
|
---|
| 1300 | is null or unset, the value of the
|
---|
| 1301 | .Ev EDITOR
|
---|
| 1302 | variable is used.
|
---|
| 1303 | If
|
---|
| 1304 | .Ev EDITOR
|
---|
| 1305 | is null or unset,
|
---|
| 1306 | .Xr ed 1
|
---|
| 1307 | is used as the editor.
|
---|
| 1308 | .It Fl l No (ell)
|
---|
| 1309 | List the commands rather than invoking an editor on them.
|
---|
| 1310 | The commands are written in the sequence indicated by
|
---|
| 1311 | the first and last operands, as affected by
|
---|
| 1312 | .Fl r ,
|
---|
| 1313 | with each command preceded by the command number.
|
---|
| 1314 | .It Fl n
|
---|
| 1315 | Suppress command numbers when listing with -l.
|
---|
| 1316 | .It Fl r
|
---|
| 1317 | Reverse the order of the commands listed (with
|
---|
| 1318 | .Fl l )
|
---|
| 1319 | or edited (with neither
|
---|
| 1320 | .Fl l
|
---|
| 1321 | nor
|
---|
| 1322 | .Fl s ) .
|
---|
| 1323 | .It Fl s
|
---|
| 1324 | Re-execute the command without invoking an editor.
|
---|
| 1325 | .It first
|
---|
| 1326 | .It last
|
---|
| 1327 | Select the commands to list or edit.
|
---|
| 1328 | The number of previous commands that
|
---|
| 1329 | can be accessed are determined by the value of the
|
---|
| 1330 | .Ev HISTSIZE
|
---|
| 1331 | variable.
|
---|
| 1332 | The value of first or last or both are one of the following:
|
---|
| 1333 | .Bl -tag -width 5n
|
---|
| 1334 | .It [+]number
|
---|
| 1335 | A positive number representing a command number; command numbers can be
|
---|
| 1336 | displayed with the
|
---|
| 1337 | .Fl l
|
---|
| 1338 | option.
|
---|
| 1339 | .It Fl number
|
---|
| 1340 | A negative decimal number representing the command that was executed
|
---|
| 1341 | number of commands previously.
|
---|
| 1342 | For example, \-1 is the immediately previous command.
|
---|
| 1343 | .El
|
---|
| 1344 | .It string
|
---|
| 1345 | A string indicating the most recently entered command that begins with
|
---|
| 1346 | that string.
|
---|
| 1347 | If the old=new operand is not also specified with
|
---|
| 1348 | .Fl s ,
|
---|
| 1349 | the string form of the first operand cannot contain an embedded equal sign.
|
---|
| 1350 | .El
|
---|
| 1351 | .Pp
|
---|
| 1352 | The following environment variables affect the execution of fc:
|
---|
| 1353 | .Bl -tag -width HISTSIZE
|
---|
| 1354 | .It Ev FCEDIT
|
---|
| 1355 | Name of the editor to use.
|
---|
| 1356 | .It Ev HISTSIZE
|
---|
| 1357 | The number of previous commands that are accessible.
|
---|
| 1358 | .El
|
---|
| 1359 | .It fg Op Ar job
|
---|
| 1360 | Move the specified job or the current job to the foreground.
|
---|
| 1361 | .It getopts Ar optstring var
|
---|
| 1362 | The
|
---|
| 1363 | .Tn POSIX
|
---|
| 1364 | .Ic getopts
|
---|
| 1365 | command, not to be confused with the
|
---|
| 1366 | .Em Bell Labs
|
---|
| 1367 | -derived
|
---|
| 1368 | .Xr getopt 1 .
|
---|
| 1369 | .Pp
|
---|
| 1370 | The first argument should be a series of letters, each of which may be
|
---|
| 1371 | optionally followed by a colon to indicate that the option requires an
|
---|
| 1372 | argument.
|
---|
| 1373 | The variable specified is set to the parsed option.
|
---|
| 1374 | .Pp
|
---|
| 1375 | The
|
---|
| 1376 | .Ic getopts
|
---|
| 1377 | command deprecates the older
|
---|
| 1378 | .Xr getopt 1
|
---|
| 1379 | utility due to its handling of arguments containing whitespace.
|
---|
| 1380 | .Pp
|
---|
| 1381 | The
|
---|
| 1382 | .Ic getopts
|
---|
| 1383 | builtin may be used to obtain options and their arguments
|
---|
| 1384 | from a list of parameters.
|
---|
| 1385 | When invoked,
|
---|
| 1386 | .Ic getopts
|
---|
| 1387 | places the value of the next option from the option string in the list in
|
---|
| 1388 | the shell variable specified by
|
---|
| 1389 | .Va var
|
---|
| 1390 | and its index in the shell variable
|
---|
| 1391 | .Ev OPTIND .
|
---|
| 1392 | When the shell is invoked,
|
---|
| 1393 | .Ev OPTIND
|
---|
| 1394 | is initialized to 1.
|
---|
| 1395 | For each option that requires an argument, the
|
---|
| 1396 | .Ic getopts
|
---|
| 1397 | builtin will place it in the shell variable
|
---|
| 1398 | .Ev OPTARG .
|
---|
| 1399 | If an option is not allowed for in the
|
---|
| 1400 | .Va optstring ,
|
---|
| 1401 | then
|
---|
| 1402 | .Ev OPTARG
|
---|
| 1403 | will be unset.
|
---|
| 1404 | .Pp
|
---|
| 1405 | .Va optstring
|
---|
| 1406 | is a string of recognized option letters (see
|
---|
| 1407 | .Xr getopt 3 ) .
|
---|
| 1408 | If a letter is followed by a colon, the option is expected to have an
|
---|
| 1409 | argument which may or may not be separated from it by whitespace.
|
---|
| 1410 | If an option character is not found where expected,
|
---|
| 1411 | .Ic getopts
|
---|
| 1412 | will set the variable
|
---|
| 1413 | .Va var
|
---|
| 1414 | to a
|
---|
| 1415 | .Dq \&? ;
|
---|
| 1416 | .Ic getopts
|
---|
| 1417 | will then unset
|
---|
| 1418 | .Ev OPTARG
|
---|
| 1419 | and write output to standard error.
|
---|
| 1420 | By specifying a colon as the first character of
|
---|
| 1421 | .Va optstring
|
---|
| 1422 | all errors will be ignored.
|
---|
| 1423 | .Pp
|
---|
| 1424 | A nonzero value is returned when the last option is reached.
|
---|
| 1425 | If there are no remaining arguments,
|
---|
| 1426 | .Ic getopts
|
---|
| 1427 | will set
|
---|
| 1428 | .Va var
|
---|
| 1429 | to the special option,
|
---|
| 1430 | .Dq -- ,
|
---|
| 1431 | otherwise, it will set
|
---|
| 1432 | .Va var
|
---|
| 1433 | to
|
---|
| 1434 | .Dq \&? .
|
---|
| 1435 | .Pp
|
---|
| 1436 | The following code fragment shows how one might process the arguments
|
---|
| 1437 | for a command that can take the options
|
---|
| 1438 | .Op a
|
---|
| 1439 | and
|
---|
| 1440 | .Op b ,
|
---|
| 1441 | and the option
|
---|
| 1442 | .Op c ,
|
---|
| 1443 | which requires an argument.
|
---|
| 1444 | .Pp
|
---|
| 1445 | .Bd -literal -offset indent
|
---|
| 1446 | while getopts abc: f
|
---|
| 1447 | do
|
---|
| 1448 | case $f in
|
---|
| 1449 | a | b) flag=$f;;
|
---|
| 1450 | c) carg=$OPTARG;;
|
---|
| 1451 | \\?) echo $USAGE; exit 1;;
|
---|
| 1452 | esac
|
---|
| 1453 | done
|
---|
| 1454 | shift `expr $OPTIND - 1`
|
---|
| 1455 | .Ed
|
---|
| 1456 | .Pp
|
---|
| 1457 | This code will accept any of the following as equivalent:
|
---|
| 1458 | .Pp
|
---|
| 1459 | .Bd -literal -offset indent
|
---|
| 1460 | cmd \-acarg file file
|
---|
| 1461 | cmd \-a \-c arg file file
|
---|
| 1462 | cmd \-carg -a file file
|
---|
| 1463 | cmd \-a \-carg \-\- file file
|
---|
| 1464 | .Ed
|
---|
| 1465 | .It hash Fl rv Ar command ...
|
---|
| 1466 | The shell maintains a hash table which remembers the
|
---|
| 1467 | locations of commands.
|
---|
| 1468 | With no arguments whatsoever,
|
---|
| 1469 | the
|
---|
| 1470 | .Ic hash
|
---|
| 1471 | command prints out the contents of this table.
|
---|
| 1472 | Entries which have not been looked at since the last
|
---|
| 1473 | .Ic cd
|
---|
| 1474 | command are marked with an asterisk; it is possible for these entries
|
---|
| 1475 | to be invalid.
|
---|
| 1476 | .Pp
|
---|
| 1477 | With arguments, the
|
---|
| 1478 | .Ic hash
|
---|
| 1479 | command removes the specified commands from the hash table (unless
|
---|
| 1480 | they are functions) and then locates them.
|
---|
| 1481 | With the
|
---|
| 1482 | .Fl v
|
---|
| 1483 | option, hash prints the locations of the commands as it finds them.
|
---|
| 1484 | The
|
---|
| 1485 | .Fl r
|
---|
| 1486 | option causes the hash command to delete all the entries in the hash table
|
---|
| 1487 | except for functions.
|
---|
| 1488 | .It inputrc Ar file
|
---|
| 1489 | Read the
|
---|
| 1490 | .Va file
|
---|
| 1491 | to set keybindings as defined by
|
---|
| 1492 | .Xr editrc 5 .
|
---|
| 1493 | .It jobid Op Ar job
|
---|
| 1494 | Print the process id's of the processes in the job.
|
---|
| 1495 | If the
|
---|
| 1496 | .Ar job
|
---|
| 1497 | argument is omitted, the current job is used.
|
---|
| 1498 | .It jobs
|
---|
| 1499 | This command lists out all the background processes
|
---|
| 1500 | which are children of the current shell process.
|
---|
| 1501 | .It pwd Op Fl LP
|
---|
| 1502 | Print the current directory.
|
---|
| 1503 | If
|
---|
| 1504 | .Fl L
|
---|
| 1505 | is specified the cached value (initially set from
|
---|
| 1506 | .Ev PWD )
|
---|
| 1507 | is checked to see if it refers to the current directory, if it does
|
---|
| 1508 | the value is printed.
|
---|
| 1509 | Otherwise the current directory name is found using
|
---|
| 1510 | .Xr getcwd(3) .
|
---|
| 1511 | The environment variable
|
---|
| 1512 | .Ev PWD
|
---|
| 1513 | is set to printed value.
|
---|
| 1514 | .Pp
|
---|
| 1515 | The default is
|
---|
| 1516 | .Ic pwd
|
---|
| 1517 | .Fl L ,
|
---|
| 1518 | but note that the builtin
|
---|
| 1519 | .Ic cd
|
---|
| 1520 | command doesn't currently support
|
---|
| 1521 | .Fl L
|
---|
| 1522 | or
|
---|
| 1523 | .Fl P
|
---|
| 1524 | and will cache (almost) the absolute path.
|
---|
| 1525 | If
|
---|
| 1526 | .Ic cd
|
---|
| 1527 | is changed,
|
---|
| 1528 | .Ic pwd
|
---|
| 1529 | may be changed to default to
|
---|
| 1530 | .Ic pwd
|
---|
| 1531 | .Fl P .
|
---|
| 1532 | .Pp
|
---|
| 1533 | If the current directory is renamed and replaced by a symlink to the
|
---|
| 1534 | same directory, or the initial
|
---|
| 1535 | .Ev PWD
|
---|
| 1536 | value followed a symbolic link, then the cached value may not
|
---|
| 1537 | be the absolute path.
|
---|
| 1538 | .Pp
|
---|
| 1539 | The builtin command may differ from the program of the same name because
|
---|
| 1540 | the program will use
|
---|
| 1541 | .Ev PWD
|
---|
| 1542 | and the builtin uses a separately cached value.
|
---|
| 1543 | .It Xo read Op Fl p Ar prompt
|
---|
| 1544 | .Op Fl r
|
---|
| 1545 | .Ar variable
|
---|
| 1546 | .Op Ar ...
|
---|
| 1547 | .Xc
|
---|
| 1548 | The prompt is printed if the
|
---|
| 1549 | .Fl p
|
---|
| 1550 | option is specified and the standard input is a terminal.
|
---|
| 1551 | Then a line is read from the standard input.
|
---|
| 1552 | The trailing newline is deleted from the
|
---|
| 1553 | line and the line is split as described in the section on word splitting
|
---|
| 1554 | above, and the pieces are assigned to the variables in order.
|
---|
| 1555 | If there are more pieces than variables, the remaining pieces
|
---|
| 1556 | (along with the characters in
|
---|
| 1557 | .Ev IFS
|
---|
| 1558 | that separated them) are assigned to the last variable.
|
---|
| 1559 | If there are more variables than pieces,
|
---|
| 1560 | the remaining variables are assigned the null string.
|
---|
| 1561 | The
|
---|
| 1562 | .Ic read
|
---|
| 1563 | builtin will indicate success unless EOF is encountered on input, in
|
---|
| 1564 | which case failure is returned.
|
---|
| 1565 | .Pp
|
---|
| 1566 | By default, unless the
|
---|
| 1567 | .Fl r
|
---|
| 1568 | option is specified, the backslash
|
---|
| 1569 | .Dq \e
|
---|
| 1570 | acts as an escape character, causing the following character to be treated
|
---|
| 1571 | literally.
|
---|
| 1572 | If a backslash is followed by a newline, the backslash and the
|
---|
| 1573 | newline will be deleted.
|
---|
| 1574 | .It readonly Ar name ...
|
---|
| 1575 | .It readonly Fl p
|
---|
| 1576 | The specified names are marked as read only, so that they cannot be
|
---|
| 1577 | subsequently modified or unset.
|
---|
| 1578 | The shell allows the value of a variable
|
---|
| 1579 | to be set at the same time it is marked read only by writing
|
---|
| 1580 | .Pp
|
---|
| 1581 | .Dl readonly name=value
|
---|
| 1582 | .Pp
|
---|
| 1583 | With no arguments the readonly command lists the names of all read only
|
---|
| 1584 | variables.
|
---|
| 1585 | With the
|
---|
| 1586 | .Fl p
|
---|
| 1587 | option specified the output will be formatted suitably for non-interactive use.
|
---|
| 1588 | .Pp
|
---|
| 1589 | .It Xo set
|
---|
| 1590 | .Oo {
|
---|
| 1591 | .Fl options | Cm +options | Cm -- }
|
---|
| 1592 | .Oc Ar arg ...
|
---|
| 1593 | .Xc
|
---|
| 1594 | The
|
---|
| 1595 | .Ic set
|
---|
| 1596 | command performs three different functions.
|
---|
| 1597 | .Pp
|
---|
| 1598 | With no arguments, it lists the values of all shell variables.
|
---|
| 1599 | .Pp
|
---|
| 1600 | If options are given, it sets the specified option
|
---|
| 1601 | flags, or clears them as described in the section called
|
---|
| 1602 | .Sx Argument List Processing .
|
---|
| 1603 | .Pp
|
---|
| 1604 | The third use of the set command is to set the values of the shell's
|
---|
| 1605 | positional parameters to the specified args.
|
---|
| 1606 | To change the positional
|
---|
| 1607 | parameters without changing any options, use
|
---|
| 1608 | .Dq --
|
---|
| 1609 | as the first argument to set.
|
---|
| 1610 | If no args are present, the set command
|
---|
| 1611 | will clear all the positional parameters (equivalent to executing
|
---|
| 1612 | .Dq shift $# . )
|
---|
| 1613 | .It setvar Ar variable Ar value
|
---|
| 1614 | Assigns value to variable.
|
---|
| 1615 | (In general it is better to write
|
---|
| 1616 | variable=value rather than using
|
---|
| 1617 | .Ic setvar .
|
---|
| 1618 | .Ic setvar
|
---|
| 1619 | is intended to be used in
|
---|
| 1620 | functions that assign values to variables whose names are passed as
|
---|
| 1621 | parameters.)
|
---|
| 1622 | .It shift Op Ar n
|
---|
| 1623 | Shift the positional parameters n times.
|
---|
| 1624 | A
|
---|
| 1625 | .Ic shift
|
---|
| 1626 | sets the value of
|
---|
| 1627 | .Va $1
|
---|
| 1628 | to the value of
|
---|
| 1629 | .Va $2 ,
|
---|
| 1630 | the value of
|
---|
| 1631 | .Va $2
|
---|
| 1632 | to the value of
|
---|
| 1633 | .Va $3 ,
|
---|
| 1634 | and so on, decreasing
|
---|
| 1635 | the value of
|
---|
| 1636 | .Va $#
|
---|
| 1637 | by one.
|
---|
| 1638 | If there are zero positional parameters,
|
---|
| 1639 | .Ic shift
|
---|
| 1640 | does nothing.
|
---|
| 1641 | .It Xo trap
|
---|
| 1642 | .Op Fl l
|
---|
| 1643 | .Xc
|
---|
| 1644 | .It Xo trap
|
---|
| 1645 | .Op Ar action
|
---|
| 1646 | .Ar signal ...
|
---|
| 1647 | .Xc
|
---|
| 1648 | Cause the shell to parse and execute action when any of the specified
|
---|
| 1649 | signals are received.
|
---|
| 1650 | The signals are specified by signal number or as the name of the signal.
|
---|
| 1651 | If
|
---|
| 1652 | .Ar signal
|
---|
| 1653 | is
|
---|
| 1654 | .Li 0 ,
|
---|
| 1655 | the action is executed when the shell exits.
|
---|
| 1656 | .Ar action
|
---|
| 1657 | may be null, which cause the specified signals to be ignored.
|
---|
| 1658 | With
|
---|
| 1659 | .Ar action
|
---|
| 1660 | omitted or set to `-' the specified signals are set to their default action.
|
---|
| 1661 | When the shell forks off a subshell, it resets trapped (but not ignored)
|
---|
| 1662 | signals to the default action.
|
---|
| 1663 | The
|
---|
| 1664 | .Ic trap
|
---|
| 1665 | command has no effect on signals that were
|
---|
| 1666 | ignored on entry to the shell.
|
---|
| 1667 | Issuing
|
---|
| 1668 | .Ic trap
|
---|
| 1669 | with option
|
---|
| 1670 | .Ar -l
|
---|
| 1671 | will print a list of valid signal names.
|
---|
| 1672 | .Ic trap
|
---|
| 1673 | without any arguments cause it to write a list of signals and their
|
---|
| 1674 | associated action to the standard output in a format that is suitable
|
---|
| 1675 | as an input to the shell that achieves the same trapping results.
|
---|
| 1676 | .Pp
|
---|
| 1677 | Examples:
|
---|
| 1678 | .Pp
|
---|
| 1679 | .Dl trap
|
---|
| 1680 | .Pp
|
---|
| 1681 | List trapped signals and their corresponding action
|
---|
| 1682 | .Pp
|
---|
| 1683 | .Dl trap -l
|
---|
| 1684 | .Pp
|
---|
| 1685 | Print a list of valid signals
|
---|
| 1686 | .Pp
|
---|
| 1687 | .Dl trap '' INT QUIT tstp 30
|
---|
| 1688 | .Pp
|
---|
| 1689 | Ignore signals INT QUIT TSTP USR1
|
---|
| 1690 | .Pp
|
---|
| 1691 | .Dl trap date INT
|
---|
| 1692 | .Pp
|
---|
| 1693 | Print date upon receiving signal INT
|
---|
| 1694 | .It type Op Ar name ...
|
---|
| 1695 | Interpret each name as a command and print the resolution of the command
|
---|
| 1696 | search.
|
---|
| 1697 | Possible resolutions are:
|
---|
| 1698 | shell keyword, alias, shell builtin,
|
---|
| 1699 | command, tracked alias and not found.
|
---|
| 1700 | For aliases the alias expansion is
|
---|
| 1701 | printed; for commands and tracked aliases the complete pathname of the
|
---|
| 1702 | command is printed.
|
---|
| 1703 | .It ulimit Xo
|
---|
| 1704 | .Op Fl H \*(Ba Fl S
|
---|
| 1705 | .Op Fl a \*(Ba Fl tfdscmlpn Op Ar value
|
---|
| 1706 | .Xc
|
---|
| 1707 | Inquire about or set the hard or soft limits on processes or set new
|
---|
| 1708 | limits.
|
---|
| 1709 | The choice between hard limit (which no process is allowed to
|
---|
| 1710 | violate, and which may not be raised once it has been lowered) and soft
|
---|
| 1711 | limit (which causes processes to be signaled but not necessarily killed,
|
---|
| 1712 | and which may be raised) is made with these flags:
|
---|
| 1713 | .Bl -tag -width Fl
|
---|
| 1714 | .It Fl H
|
---|
| 1715 | set or inquire about hard limits
|
---|
| 1716 | .It Fl S
|
---|
| 1717 | set or inquire about soft limits.
|
---|
| 1718 | If neither
|
---|
| 1719 | .Fl H
|
---|
| 1720 | nor
|
---|
| 1721 | .Fl S
|
---|
| 1722 | is specified, the soft limit is displayed or both limits are set.
|
---|
| 1723 | If both are specified, the last one wins.
|
---|
| 1724 | .El
|
---|
| 1725 | .Pp
|
---|
| 1726 | .Bl -tag -width Fl
|
---|
| 1727 | The limit to be interrogated or set, then, is chosen by specifying
|
---|
| 1728 | any one of these flags:
|
---|
| 1729 | .It Fl a
|
---|
| 1730 | show all the current limits
|
---|
| 1731 | .It Fl b
|
---|
| 1732 | show or set the limit on the socket buffer size of a process (in bytes)
|
---|
| 1733 | .It Fl t
|
---|
| 1734 | show or set the limit on CPU time (in seconds)
|
---|
| 1735 | .It Fl f
|
---|
| 1736 | show or set the limit on the largest file that can be created
|
---|
| 1737 | (in 512-byte blocks)
|
---|
| 1738 | .It Fl d
|
---|
| 1739 | show or set the limit on the data segment size of a process (in kilobytes)
|
---|
| 1740 | .It Fl s
|
---|
| 1741 | show or set the limit on the stack size of a process (in kilobytes)
|
---|
| 1742 | .It Fl c
|
---|
| 1743 | show or set the limit on the largest core dump size that can be produced
|
---|
| 1744 | (in 512-byte blocks)
|
---|
| 1745 | .It Fl m
|
---|
| 1746 | show or set the limit on the total physical memory that can be
|
---|
| 1747 | in use by a process (in kilobytes)
|
---|
| 1748 | .It Fl l
|
---|
| 1749 | show or set the limit on how much memory a process can lock with
|
---|
| 1750 | .Xr mlock 2
|
---|
| 1751 | (in kilobytes)
|
---|
| 1752 | .It Fl p
|
---|
| 1753 | show or set the limit on the number of processes this user can
|
---|
| 1754 | have at one time
|
---|
| 1755 | .It Fl n
|
---|
| 1756 | show or set the limit on the number of files a process can have open at once
|
---|
| 1757 | .El
|
---|
| 1758 | .Pp
|
---|
| 1759 | If none of these is specified, it is the limit on file size that is shown
|
---|
| 1760 | or set.
|
---|
| 1761 | If value is specified, the limit is set to that number; otherwise
|
---|
| 1762 | the current limit is displayed.
|
---|
| 1763 | .Pp
|
---|
| 1764 | Limits of an arbitrary process can be displayed or set using the
|
---|
| 1765 | .Xr sysctl 8
|
---|
| 1766 | utility.
|
---|
| 1767 | .Pp
|
---|
| 1768 | .It umask Op Ar mask
|
---|
| 1769 | Set the value of umask (see
|
---|
| 1770 | .Xr umask 2 )
|
---|
| 1771 | to the specified octal value.
|
---|
| 1772 | If the argument is omitted, the umask value is printed.
|
---|
| 1773 | .It unalias Xo
|
---|
| 1774 | .Op Fl a
|
---|
| 1775 | .Op Ar name
|
---|
| 1776 | .Xc
|
---|
| 1777 | If
|
---|
| 1778 | .Ar name
|
---|
| 1779 | is specified, the shell removes that alias.
|
---|
| 1780 | If
|
---|
| 1781 | .Fl a
|
---|
| 1782 | is specified, all aliases are removed.
|
---|
| 1783 | .It unset Ar name ...
|
---|
| 1784 | The specified variables and functions are unset and unexported.
|
---|
| 1785 | If a given name corresponds to both a variable and a function, both
|
---|
| 1786 | the variable and the function are unset.
|
---|
| 1787 | .It wait Op Ar job
|
---|
| 1788 | Wait for the specified job to complete and return the exit status of the
|
---|
| 1789 | last process in the job.
|
---|
| 1790 | If the argument is omitted, wait for all jobs to
|
---|
| 1791 | complete and then return an exit status of zero.
|
---|
| 1792 | .El
|
---|
| 1793 | .Ss Command Line Editing
|
---|
| 1794 | When
|
---|
| 1795 | .Nm
|
---|
| 1796 | is being used interactively from a terminal, the current command
|
---|
| 1797 | and the command history (see
|
---|
| 1798 | .Ic fc
|
---|
| 1799 | in
|
---|
| 1800 | .Sx Builtins )
|
---|
| 1801 | can be edited using emacs-mode or vi-mode command-line editing.
|
---|
| 1802 | The command
|
---|
| 1803 | .Ql set -o emacs
|
---|
| 1804 | enables emacs-mode editing.
|
---|
| 1805 | The command
|
---|
| 1806 | .Ql set -o vi
|
---|
| 1807 | enables vi-mode editing and places sh into vi insert mode.
|
---|
| 1808 | (See the
|
---|
| 1809 | .Sx Argument List Processing
|
---|
| 1810 | section above.)
|
---|
| 1811 | .Pp
|
---|
| 1812 | The vi mode uses commands similar to a subset of those described in the
|
---|
| 1813 | .Xr vi 1
|
---|
| 1814 | man page.
|
---|
| 1815 | With vi-mode
|
---|
| 1816 | enabled, sh can be switched between insert mode and command mode.
|
---|
| 1817 | It's similar to vi: typing
|
---|
| 1818 | .Aq ESC
|
---|
| 1819 | will throw you into command VI command mode.
|
---|
| 1820 | Hitting
|
---|
| 1821 | .Aq return
|
---|
| 1822 | while in command mode will pass the line to the shell.
|
---|
| 1823 | .Pp
|
---|
| 1824 | The emacs mode uses commands similar to a subset available in
|
---|
| 1825 | the emacs editor.
|
---|
| 1826 | With emacs-mode enabled, special keys can be used to modify the text
|
---|
| 1827 | in the buffer using the control key.
|
---|
| 1828 | .Pp
|
---|
| 1829 | .Nm
|
---|
| 1830 | uses the
|
---|
| 1831 | .Xr editline 3
|
---|
| 1832 | library.
|
---|
| 1833 | .Sh EXIT STATUS
|
---|
| 1834 | Errors that are detected by the shell, such as a syntax error, will cause the
|
---|
| 1835 | shell to exit with a non-zero exit status.
|
---|
| 1836 | If the shell is not an
|
---|
| 1837 | interactive shell, the execution of the shell file will be aborted.
|
---|
| 1838 | Otherwise
|
---|
| 1839 | the shell will return the exit status of the last command executed, or
|
---|
| 1840 | if the exit builtin is used with a numeric argument, it will return the
|
---|
| 1841 | argument.
|
---|
| 1842 | .Sh ENVIRONMENT
|
---|
| 1843 | .Bl -tag -width MAILCHECK
|
---|
| 1844 | .It Ev HOME
|
---|
| 1845 | Set automatically by
|
---|
| 1846 | .Xr login 1
|
---|
| 1847 | from the user's login directory in the password file
|
---|
| 1848 | .Pq Xr passwd 5 .
|
---|
| 1849 | This environment variable also functions as the default argument for the
|
---|
| 1850 | cd builtin.
|
---|
| 1851 | .It Ev PATH
|
---|
| 1852 | The default search path for executables.
|
---|
| 1853 | See the above section
|
---|
| 1854 | .Sx Path Search .
|
---|
| 1855 | .It Ev CDPATH
|
---|
| 1856 | The search path used with the cd builtin.
|
---|
| 1857 | .It Ev LANG
|
---|
| 1858 | The string used to specify localization information that allows users
|
---|
| 1859 | to work with different culture-specific and language conventions.
|
---|
| 1860 | See
|
---|
| 1861 | .Xr nls 7 .
|
---|
| 1862 | .It Ev MAIL
|
---|
| 1863 | The name of a mail file, that will be checked for the arrival of new mail.
|
---|
| 1864 | Overridden by
|
---|
| 1865 | .Ev MAILPATH .
|
---|
| 1866 | .It Ev MAILCHECK
|
---|
| 1867 | The frequency in seconds that the shell checks for the arrival of mail
|
---|
| 1868 | in the files specified by the
|
---|
| 1869 | .Ev MAILPATH
|
---|
| 1870 | or the
|
---|
| 1871 | .Ev MAIL
|
---|
| 1872 | file.
|
---|
| 1873 | If set to 0, the check will occur at each prompt.
|
---|
| 1874 | .It Ev MAILPATH
|
---|
| 1875 | A colon
|
---|
| 1876 | .Dq \&:
|
---|
| 1877 | separated list of file names, for the shell to check for incoming mail.
|
---|
| 1878 | This environment setting overrides the
|
---|
| 1879 | .Ev MAIL
|
---|
| 1880 | setting.
|
---|
| 1881 | There is a maximum of 10 mailboxes that can be monitored at once.
|
---|
| 1882 | .It Ev PS1
|
---|
| 1883 | The primary prompt string, which defaults to
|
---|
| 1884 | .Dq $ \ ,
|
---|
| 1885 | unless you are the superuser, in which case it defaults to
|
---|
| 1886 | .Dq # \ .
|
---|
| 1887 | .It Ev PS2
|
---|
| 1888 | The secondary prompt string, which defaults to
|
---|
| 1889 | .Dq \*[Gt] \ .
|
---|
| 1890 | .It Ev PS4
|
---|
| 1891 | Output before each line when execution trace (set -x) is enabled,
|
---|
| 1892 | defaults to
|
---|
| 1893 | .Dq + \ .
|
---|
| 1894 | .It Ev IFS
|
---|
| 1895 | Input Field Separators.
|
---|
| 1896 | This is normally set to
|
---|
| 1897 | .Aq space ,
|
---|
| 1898 | .Aq tab ,
|
---|
| 1899 | and
|
---|
| 1900 | .Aq newline .
|
---|
| 1901 | See the
|
---|
| 1902 | .Sx White Space Splitting
|
---|
| 1903 | section for more details.
|
---|
| 1904 | .It Ev TERM
|
---|
| 1905 | The default terminal setting for the shell.
|
---|
| 1906 | This is inherited by
|
---|
| 1907 | children of the shell, and is used in the history editing modes.
|
---|
| 1908 | .It Ev HISTSIZE
|
---|
| 1909 | The number of lines in the history buffer for the shell.
|
---|
| 1910 | .El
|
---|
| 1911 | .Sh FILES
|
---|
| 1912 | .Bl -item -width HOMEprofilexxxx
|
---|
| 1913 | .It
|
---|
| 1914 | .Pa $HOME/.profile
|
---|
| 1915 | .It
|
---|
| 1916 | .Pa /etc/profile
|
---|
| 1917 | .El
|
---|
| 1918 | .Sh SEE ALSO
|
---|
| 1919 | .Xr csh 1 ,
|
---|
| 1920 | .Xr echo 1 ,
|
---|
| 1921 | .Xr getopt 1 ,
|
---|
| 1922 | .Xr ksh 1 ,
|
---|
| 1923 | .Xr login 1 ,
|
---|
| 1924 | .Xr printf 1 ,
|
---|
| 1925 | .Xr test 1 ,
|
---|
| 1926 | .Xr editline 3 ,
|
---|
| 1927 | .Xr getopt 3 ,
|
---|
| 1928 | .\" .Xr profile 4 ,
|
---|
| 1929 | .Xr editrc 5 ,
|
---|
| 1930 | .Xr passwd 5 ,
|
---|
| 1931 | .Xr environ 7 ,
|
---|
| 1932 | .Xr nls 7 ,
|
---|
| 1933 | .Xr sysctl 8
|
---|
| 1934 | .Sh HISTORY
|
---|
| 1935 | A
|
---|
| 1936 | .Nm
|
---|
| 1937 | command appeared in
|
---|
| 1938 | .At v1 .
|
---|
| 1939 | It was, however, unmaintainable so we wrote this one.
|
---|
| 1940 | .Sh BUGS
|
---|
| 1941 | Setuid shell scripts should be avoided at all costs, as they are a
|
---|
| 1942 | significant security risk.
|
---|
| 1943 | .Pp
|
---|
| 1944 | PS1, PS2, and PS4 should be subject to parameter expansion before
|
---|
| 1945 | being displayed.
|
---|
| 1946 | .Pp
|
---|
| 1947 | The characters generated by filename completion should probably be quoted
|
---|
| 1948 | to ensure that the filename is still valid after the input line has been
|
---|
| 1949 | processed.
|
---|