Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
bash(1)Part2
Edit
PageHistory
Diff
Info
LikePages
!!BASH MAN PAGE (Part 2) __Navigation__%%% This man page has been split into 7 pages:%%% bash(1) * NAME * SYNOPSIS * COPYRIGHT * DESCRIPTION * OPTIONS * ARGUMENTS * INVOCATION __Part 2__ * __DEFINITIONS__ * __RESERVED WORDS__ * __SHELL GRAMMAR__ * __COMMENTS__ * __QUOTING__ [bash(1)Part3] * PARAMETERS [bash(1)Part4] * EXPANSION [bash(1)Part5] * REDIRECTION * ALIASES * FUNCTIONS * ARITHMETIC EVALUATION * CONDITIONAL EXPRESSIONS * SIMPLE COMMAND EXPANSION * COMMAND EXECUTION * COMMAND EXECUTION ENVIRONMENT * ENVIRONMENT * EXIT STATUS * SIGNALS * JOB CONTROL * PROMPTING [bash(1)Part6] * READLINE * HISTORY * HISTORY EXPANSION [bash(1)Part7] * SHELL BUILTIN COMMANDS * RESTRICTED SHELL * SEE ALSO * FILES * AUTHORS * BUG REPORTS * BUGS ---- !!DEFINITIONS The following definitions are used throughout the rest of this document. ;__blank __ : A space or tab. ;__word__ : A sequence of characters considered as a single unit by the shell. Also known as a __token__ . ;__name__ : A ''word'' consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an __identifier__ . ;__metacharacter__ : A character that, when unquoted, separates words. One of the following: __| & ; ( ) < > space tab__ ;__control operator__ : A ''token'' that performs a control function. It is one of the following symbols: __|| & && ; ;; ( ) | <newline>__ !!RESERVED WORDS ''Reserved words'' are words that have a special meaning to the shell. The following words are recognized as reserved when unquoted and either the first word of a simple command (see __SHELL GRAMMAR__ below) or the third word of a __case __ or __for__ command: .B ! case do done elif else esac fi for function if in select then until while { } time [[[[ ]] !!SHELL GRAMMAR !Simple Commands A ''simple command'' is a sequence of optional variable assignments followed by __blank__-separated words and redirections, and terminated by a ''control operator''. The first word specifies the command to be executed. The remaining words are passed as arguments to the invoked command. The return value of a ''simple command'' is its exit status, or 128+''n'' if the command is terminated by signal ''n'' . !Pipelines A ''pipeline'' is a sequence of one or more commands separated by the character __|__ . The format for a pipeline is: [[__time__ [[__-p__]] [[ ! ] ''command'' [[ __|__ ''command2'' ... ] The standard output of ''command'' is connected to the standard input of ''command2'' . This connection is performed before any redirections specified by the command (see __REDIRECTION__ below). If the reserved word __!__ precedes a pipeline, the exit status of that pipeline is the logical NOT of the exit status of the last command. Otherwise, the status of the pipeline is the exit status of the last command. The shell waits for all commands in the pipeline to terminate before returning a value. If the __time__ reserved word precedes a pipeline, the elapsed as well as user and system time consumed by its execution are reported when the pipeline terminates. The __-p__ option changes the output format to that specified by POSIX. The __TIMEFORMAT__ variable may be set to a format string that specifies how the timing information should be displayed; see the description of __TIMEFORMAT__ under __Shell Variables__ below. Each command in a pipeline is executed as a separate process (i.e., in a subshell). !Lists A ''list'' is a sequence of one or more pipelines separated by one of the operators __;__ , __&__ , __&&__ , or __||__ , and optionally terminated by one of __;__ , __&__ , or __<newline>__ . Of these list operators, __&&__ and __||__ have equal precedence, followed by __;__ and __&,__ which have equal precedence. If a command is terminated by the control operator __&__ , the shell executes the command in the ''background'' in a subshell. The shell does not wait for the command to finish, and the return status is 0. Commands separated by a __;__ are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed. The control operators __&&__ and __||__ denote AND lists and OR lists, respectively. An AND list has the form ''command1'' __&&__ ''command2'' ''command2'' is executed if, and only if, ''command1'' returns an exit status of zero. An OR list has the form ''command1'' __||__ ''command2'' ''command2'' is executed if and only if ''command1'' returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list. !Compound Commands A ''compound command'' is one of the following: ;(''list'') : ''list'' is executed in a subshell. Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes. The return status is the exit status of ''list''. ;{ ''list''; } : ''list'' is simply executed in the current shell environment. ''list'' must be terminated with a newline or semicolon. This is known as a ''group command''. The return status is the exit status of ''list''. ;((''expression'')) : The ''expression'' is evaluated according to the rules described below under __ARITHMETIC EVALUATION__ . If the value of the expression is non-zero, the return status is 0; otherwise the return status is 1. This is exactly equivalent to __let "''expression''__". ;__[[[[__ ''expression'' __]]__ : Return a status of 0 or 1 depending on the evaluation of the conditional expression ''expression''. Expressions are composed of the primaries described below under __CONDITIONAL EXPRESSIONS__ . Word splitting and pathname expansion are not performed on the words between the __[[[[__ and __]]__; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. .sp 1When the __==__ and __!=__ operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below under __Pattern Matching__. The return value is 0 if the string matches or does not match the pattern, respectively, and 1 otherwise. Any part of the pattern may be quoted to force it to be matched as a string. .sp 1Expressions may be combined using the following operators, listed in decreasing order of precedence: .sp 1 ;__( ''expression'' )__ : Returns the value of ''expression''. This may be used to override the normal precedence of operators. ;__! ''expression''__ : True if ''expression'' is false. ;''expression1'' __&&__ ''expression2'' : True if both ''expression1'' and ''expression2'' are true. ; ''expression1'' __||__ ''expression2'' : True if either ''expression1'' or ''expression2'' is true. The __&&__ and __||__ operators do not execute ''expression2'' if the value of ''expression1'' is sufficient to determine the return value of the entire conditional expression. ;__for__ ''name'' [[ __in__ ''word'' ] ; __do__ ''list'' ; __done__ : The list of words following __in__ is expanded, generating a list of items. The variable ''name'' is set to each element of this list in turn, and ''list'' is executed each time. If the __in__ ''word'' is omitted, the __for__ command executes ''list'' once for each positional parameter that is set (see __PARAMETERS__ below). The return status is the exit status of the last command that executes. If the expansion of the items following __in__ results in an empty list, no commands are executed, and the return status is 0. ;__for__ (( ''expr1'' ; ''expr2'' ; ''expr3'' )) ; __do__ ''list'' ; __done__ : First, the arithmetic expression ''expr1'' is evaluated according to the rules described below under __ARITHMETIC EVALUATION__ . The arithmetic expression ''expr2'' is then evaluated repeatedly until it evaluates to zero. Each time ''expr2'' evaluates to a non-zero value, ''list'' is executed and the arithmetic expression ''expr3'' is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in ''list'' that is executed, or false if any of the expressions is invalid. ;__select__ ''name'' [[ __in__ ''word'' ] ; __do__ ''list'' ; __done__ : The list of words following __in__ is expanded, generating a list of items. The set of expanded words is printed on the standard error, each preceded by a number. If the __in__ ''word'' is omitted, the positional parameters are printed (see __PARAMETERS__ below). The __PS3__ prompt is then displayed and a line read from the standard input. If the line consists of a number corresponding to one of the displayed words, then the value of ''name'' is set to that word. If the line is empty, the words and prompt are displayed again. If EOF is read, the command completes. Any other value read causes ''name'' to be set to null. The line read is saved in the variable __REPLY__ . The ''list'' is executed after each selection until a __break__ or __return__ command is executed. The exit status of __select__ is the exit status of the last command executed in ''list'' , or zero if no commands were executed. ;__case__ ''word'' __in__ [[ [[(] ''pattern'' [[ __|__ ''pattern'' ] ... ) ''list'' ;; ] ... __esac__: A __case__ command first expands ''word'', and tries to match it against each ''pattern'' in turn, using the same matching rules as for pathname expansion (see __Pathname Expansion__ below). When a match is found, the corresponding ''list'' is executed. After the first match, no subsequent matches are attempted. The exit status is zero if no pattern matches. Otherwise, it is the exit status of the last command executed in ''list''. ;__if__ ''list''; __then__ ''list;'' \ : [[ __elif__ ''list''; __then__ ''list''; ] ... \ [[ __else__ ''list''; ] __fi__ The __if __ ''list'' is executed. If its exit status is zero, the __then__ ''list'' is executed. Otherwise, each __elif__ ''list'' is executed in turn, and if its exit status is zero, the corresponding __then__ ''list'' is executed and the command completes. Otherwise, the __else__ ''list'' is executed, if present. The exit status is the exit status of the last command executed, or zero if no condition tested true. __while__ ''list''; __do__ ''list''; __done__ ;__until__ ''list''; __do__ ''list''; __done__ : The __while__ command continuously executes the __do__ ''list'' as long as the last command in ''list'' returns an exit status of zero. The __until__ command is identical to the __while__ command, except that the test is negated; the __do__ ''list'' is executed as long as the last command in ''list'' returns a non-zero exit status. The exit status of the __while__ and __until__ commands is the exit status of the last __do__ ''list'' command executed, or zero if none was executed. ;[[ __function__ ] ''name'' () { ''list''; } : This defines a function named ''name''. The ''body'' of the function is the ''list'' of commands between { and }. This list is executed whenever ''name'' is specified as the name of a simple command. The exit status of a function is the exit status of the last command executed in the body. (See __FUNCTIONS__ below.) !!COMMENTS In a non-interactive shell, or an interactive shell in which the __interactive_comments__ option to the __shopt__ builtin is enabled (see __SHELL BUILTIN COMMANDS__ below), a word beginning with __#__ causes that word and all remaining characters on that line to be ignored. An interactive shell without the __interactive_comments__ option enabled does not allow comments. The __interactive_comments__ option is on by default in interactive shells. !!QUOTING ''Quoting'' is used to remove the special meaning of certain characters or words to the shell. Quoting can be used to disable special treatment for special characters, to prevent reserved words from being recognized as such, and to prevent parameter expansion. Each of the ''metacharacters'' listed above under __DEFINITIONS__ has special meaning to the shell and must be quoted if it is to represent itself. When the command history expansion facilities are being used, the ''history expansion'' character, usually __!__, must be quoted to prevent history expansion. There are three quoting mechanisms: the ''escape character'' , single quotes, and double quotes. A non-quoted backslash (__\__) is the ''escape character'' . It preserves the literal value of the next character that follows, with the exception of <newline>. If a __\__<newline> pair appears, and the backslash is not itself quoted, the __\__<newline> is treated as a line continuation (that is, it is removed from the input stream and effectively ignored). Enclosing characters in single quotes preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash. Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of __$__ , __`__ , and __\__ . The characters __$__ and __`__ retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: __$__ , __`__ , __"__, __\__ , or __<newline>__ . A double quote may be quoted within double quotes by preceding it with a backslash. The special parameters __*__ and __@__ have special meaning when in double quotes (see __PARAMETERS__ below). Words of the form __$__'''string''' are treated specially. The word expands to ''string'', with backslash-escaped characters replaced as specifed by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: ;__\a__ : alert (bell) ;__\b__ : backspace ;__\e__ : an escape character ;__\f__ : form feed ;__\n__ : new line ;__\r__ : carriage return ;__\t__ : horizontal tab ;__\v__ : vertical tab ;__\\e__ : backslash ;__\'__ : single quote ;__\''nnn''__ : the character whose ASCII code is the octal value ''nnn'' (one to three digits) ;__\x''nnn''__ : the character whose ASCII code is the hexadecimal value ''nnn'' (one to three digits) The expanded result is single-quoted, as if the dollar sign had not been present. A double-quoted string preceded by a dollar sign (__$__) will cause the string to be translated according to the current locale. If the current locale is __C__ or __POSIX__, the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted.
6 pages link to
bash(1)Part2
:
bash(1)Part7
bash(1)Part6
bash(1)Part4
bash(1)Part3
bash(1)
bash(1)Part5
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.