Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
bash(1)Part3
Edit
PageHistory
Diff
Info
LikePages
!!BASH MAN PAGE (Part 3) __Navigation__%%% This man page has been split into 7 pages:%%% bash(1) * NAME * SYNOPSIS * COPYRIGHT * DESCRIPTION * OPTIONS * ARGUMENTS * INVOCATION [bash(1)Part2] * DEFINITIONS * RESERVED WORDS * SHELL GRAMMAR * COMMENTS * QUOTING __Part 3__ * __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 ---- !!PARAMETERS A ''parameter'' is an entity that stores values. It can be a ''name'' , a number, or one of the special characters listed below under __Special Parameters__ . For the shell's purposes, a ''variable'' is a parameter denoted by a ''name'' . A parameter is set if it has been assigned a value. The null string is a valid value. Once a variable is set, it may be unset only by using the __unset__ builtin command (see __SHELL BUILTIN COMMANDS__ below). A ''variable'' may be assigned to by a statement of the form ''name''=[[''value''] If ''value'' is not given, the variable is assigned the null string. All ''values'' undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal (see __EXPANSION__ below). If the variable has its __integer__ attribute set (see __declare__ below in __SHELL BUILTIN COMMANDS__ ) then ''value'' is subject to arithmetic expansion even if the $((...)) expansion is not used (see __Arithmetic Expansion__ below). Word splitting is not performed, with the exception of __"$@"__ as explained below under __Special Parameters__ . Pathname expansion is not performed. !Positional Parameters A ''positional parameter'' is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell's arguments when it is invoked, and may be reassigned using the __set__ builtin command. Positional parameters may not be assigned to with assignment statements. The positional parameters are temporarily replaced when a shell function is executed (see __FUNCTIONS__ below). When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces (see __EXPANSION__ below). !Special Parameters The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. ;__*__ : Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the __IFS__ special variable. That is, "__$*__" is equivalent to "__$1__''c''__$2__''c''__...__", where ''c'' is the first character of the value of the __IFS__ variable. If __IFS__ is unset, the parameters are separated by spaces. If __IFS__ is null, the parameters are joined without intervening separators. ;__@__ : Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "__$@__" is equivalent to "__$1__" "__$2__" ... When there are no positional parameters, "__$@__" and __$@__ expand to nothing (i.e., they are removed). ;__#__ : Expands to the number of positional parameters in decimal. ;__?__ : Expands to the status of the most recently executed foreground pipeline. ;__-__ : Expands to the current option flags as specified upon invocation, by the __set__ builtin command, or those set by the shell itself (such as the __-i__ option). ;__$__ : Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell. ;__!__ : Expands to the process ID of the most recently executed background (asynchronous) command. ;__0__ : Expands to the name of the shell or shell script. This is set at shell initialization. If __bash__ is invoked with a file of commands, __$0__ is set to the name of that file. If __bash__ is started with the __-c__ option, then __$0__ is set to the first argument after the string to be executed, if one is present. Otherwise, it is set to the file name used to invoke __bash__ , as given by argument zero. ;_____ : At shell startup, set to the absolute file name of the shell or shell script being executed as passed in the argument list. Subsequently, expands to the last argument to the previous command, after expansion. Also set to the full file name of each command executed and placed in the environment exported to that command. When checking mail, this parameter holds the name of the mail file currently being checked. !Shell Variables The following variables are set by the shell: ;__PPID__ : The process ID of the shell's parent. This variable is readonly. ;__PWD__ : The current working directory as set by the __cd__ command. ;__OLDPWD__ : The previous working directory as set by the __cd__ command. ;__REPLY__ : Set to the line of input read by the __read__ builtin command when no arguments are supplied. ;__UID__ : Expands to the user ID of the current user, initialized at shell startup. This variable is readonly. ;__EUID__ : Expands to the effective user ID of the current user, initialized at shell startup. This variable is readonly. ;__GROUPS__ : An array variable containing the list of groups of which the current user is a member. Assignments to __GROUPS__ have no effect and return an error status. If __GROUPS__ is unset, it loses its special properties, even if it is subsequently reset. ;__BASH__ : Expands to the full file name used to invoke this instance of __bash__ . ;__BASH_VERSION__ : Expands to a string describing the version of this instance of __bash__ . ;__BASH_VERSINFO__ : A readonly array variable whose members hold version information for this instance of __bash__ . The values assigned to the array members are as follows: ;__BASH_VERSINFO[[0]__ : The major version number (the ''release''). ;__BASH_VERSINFO[[1]__ : The minor version number (the ''version''). ;__BASH_VERSINFO[[2]__ : The patch level. ;__BASH_VERSINFO[[3]__ : The build version. ;__BASH_VERSINFO[[4]__ : The release status (e.g., ''beta1''). ;__BASH_VERSINFO[[5]__ : The value of __MACHTYPE__. ;__SHLVL__ : Incremented by one each time an instance of __bash__ is started. ;__RANDOM__ : Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be initialized by assigning a value to __RANDOM__ . If __RANDOM__ is unset, it loses its special properties, even if it is subsequently reset. ;__SECONDS__ : Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to __SECONDS__ , the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. If __SECONDS__ is unset, it loses its special properties, even if it is subsequently reset. ;__LINENO__ : Each time this parameter is referenced, the shell substitutes a decimal number representing the current sequential line number (starting with 1) within a script or function. When not in a script or function, the value substituted is not guaranteed to be meaningful. If __LINENO__ is unset, it loses its special properties, even if it is subsequently reset. ;__HISTCMD__ : The history number, or index in the history list, of the current command. If __HISTCMD__ is unset, it loses its special properties, even if it is subsequently reset. ;__FUNCNAME__ : The name of any currently-executing shell function. This variable exists only when a shell function is executing. Assignments to __FUNCNAME__ have no effect and return an error status. If __FUNCNAME__ is unset, it loses its special properties, even if it is subsequently reset. ;__DIRSTACK__ : An array variable (see __Arrays__ below) containing the current contents of the directory stack. Directories appear in the stack in the order they are displayed by the __dirs__ builtin. Assigning to members of this array variable may be used to modify directories already in the stack, but the __pushd__ and __popd__ builtins must be used to add and remove directories. Assignment to this variable will not change the current directory. If __DIRSTACK__ is unset, it loses its special properties, even if it is subsequently reset. ;__PIPESTATUS__ : An array variable (see __Arrays__ below) containing a list of exit status values from the processes in the most-recently-executed foreground pipeline (which may contain only a single command). ;__OPTARG__ : The value of the last option argument processed by the __getopts__ builtin command (see __SHELL BUILTIN COMMANDS__ below). ;__OPTIND__ : The index of the next argument to be processed by the __getopts__ builtin command (see __SHELL BUILTIN COMMANDS__ below). ;__HOSTNAME__ : Automatically set to the name of the current host. ;__HOSTTYPE__ : Automatically set to a string that uniquely describes the type of machine on which __bash__ is executing. The default is system-dependent. ;__OSTYPE__ : Automatically set to a string that describes the operating system on which __bash__ is executing. The default is system-dependent. ;__MACHTYPE__ : Automatically set to a string that fully describes the system type on which __bash__ is executing, in the standard GNU ''cpu-company-system'' format. The default is system-dependent. ;__SHELLOPTS__ : A colon-separated list of enabled shell options. Each word in the list is a valid argument for the __-o__ option to the __set__ builtin command (see __SHELL BUILTIN COMMANDS__ below). The options appearing in __SHELLOPTS__ are those reported as ''on'' by __set -o__. If this variable is in the environment when __bash__ starts up, each shell option in the list will be enabled before reading any startup files. This variable is read-only. ;__COMP_WORDS__ : An array variable (see __Arrays__ below) consisting of the individual words in the current command line. This variable is available only in shell functions invoked by the programmable completion facilities (see __Programmable Completion__ below). ;__COMP_CWORD__ : An index into __${COMP_WORDS}__ of the word containing the current cursor position. This variable is available only in shell functions invoked by the programmable completion facilities (see __Programmable Completion__ below). ;__COMP_LINE__ : The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see __Programmable Completion__ below). ;__COMP_POINT__ : The index of the current cursor position relative to the beginning of the current command. If the current cursor position is at the end of the current command, the value of this variable is equal to __${#COMP_LINE}__. This variable is available only in shell functions and external commands invoked by the programmable completion facilities (see __Programmable Completion__ below). The following variables are used by the shell. In some cases, __bash__ assigns a default value to a variable; these cases are noted below. ;__IFS__ : The ''Internal Field Separator'' that is used for word splitting after expansion and to split lines into words with the __read__ builtin command. The default value is ``<space><tab><newline>". ;__PATH__ : The search path for commands. It is a colon-separated list of directories in which the shell looks for commands (see __COMMAND EXECUTION__ below). The default path is system-dependent, and is set by the administrator who installs __bash__ . A common value is "/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:.". ;__HOME__ : The home directory of the current user; the default argument for the __cd__ builtin command. The value of this variable is also used when performing tilde expansion. ;__CDPATH__ : The search path for the __cd__ command. This is a colon-separated list of directories in which the shell looks for destination directories specified by the __cd__ command. A sample value is ".:~:/usr". ;__BASH_ENV__ : If this parameter is set when __bash__ is executing a shell script, its value is interpreted as a filename containing commands to initialize the shell, as in ''~/.bashrc'' . The value of __BASH_ENV__ is subjected to parameter expansion, command substitution, and arithmetic expansion before being interpreted as a file name. __PATH__ is not used to search for the resultant file name. ;__MAIL__ : If this parameter is set to a file name and the __MAILPATH__ variable is not set, __bash__ informs the user of the arrival of mail in the specified file. ;__MAILCHECK__ : Specifies how often (in seconds) __bash__ checks for mail. The default is 60 seconds. When it is time to check for mail, the shell does so before displaying the primary prompt. If this variable is unset, or set to a value that is not a number greater than or equal to zero, the shell disables mail checking. ;__MAILPATH__ : A colon-separated list of file names to be checked for mail. The message to be printed when mail arrives in a particular file may be specified by separating the file name from the message with a `?'. When used in the text of the message, __$___ expands to the name of the current mailfile. Example: __MAILPATH__='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has mail!"' __Bash__ supplies a default value for this variable, but the location of the user mail files that it uses is system dependent (e.g., /var/mail/__$USER__). ;__PS1__ : The value of this parameter is expanded (see __PROMPTING__ below) and used as the primary prompt string. The default value is ``__\s-\v\$ __". ;__PS2__ : The value of this parameter is expanded as with __PS1__ and used as the secondary prompt string. The default is ``__> __". ;__PS3__ : The value of this parameter is used as the prompt for the __select__ command (see __SHELL GRAMMAR__ above). ;__PS4__ : The value of this parameter is expanded as with __PS1__ and the value is printed before each command __bash__ displays during an execution trace. The first character of __PS4__ is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is "__+ __". ;__TIMEFORMAT__ : The value of this parameter is used as a format string specifying how the timing information for pipelines prefixed with the __time__ reserved word should be displayed. The __%__ character introduces an escape sequence that is expanded to a time value or other information. The escape sequences and their meanings are as follows; the braces denote optional portions. ;__%%__ : A literal __%__. ;__%[[''p''][[l]R__ : The elapsed time in seconds. ;__%[[''p''][[l]U__ : The number of CPU seconds spent in user mode. ;__%[[''p''][[l]S__ : The number of CPU seconds spent in system mode. ;__%P__ : The CPU percentage, computed as (%U + %S) / %R. ;: The optional ''p'' is a digit specifying the ''precision'', the number of fractional digits after a decimal point. A value of 0 causes no decimal point or fraction to be output. At most three places after the decimal point may be specified; values of ''p'' greater than 3 are changed to 3. If ''p'' is not specified, the value 3 is used. ;: The optional __l__ specifies a longer format, including minutes, of the form ''MM''m''SS''.''FF''s. The value of ''p'' determines whether or not the fraction is included. ;: If this variable is not set, __bash__ acts as if it had the value __$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'__. If the value is null, no timing information is displayed. A trailing newline is added when the format string is displayed. ;__HISTSIZE__ : The number of commands to remember in the command history (see __HISTORY__ below). The default value is 500. ;__HISTFILE__ : The name of the file in which command history is saved (see __HISTORY__ below). The default value is ''~/.bash_history''. If unset, the command history is not saved when an interactive shell exits. ;__HISTFILESIZE__ : The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, to contain no more than that number of lines. The default value is 500. The history file is also truncated to this size after writing it when an interactive shell exits. ;__OPTERR__ : If set to the value 1, __bash__ displays error messages generated by the __getopts__ builtin command (see __SHELL BUILTIN COMMANDS__ below). __OPTERR__ is initialized to 1 each time the shell is invoked or a shell script is executed. ;__LANG__ : Used to determine the locale category for any category not specifically selected with a variable starting with __LC___. ;__LC_ALL__ : This variable overrides the value of __LANG__ and any other __LC___ variable specifying a locale category. ;__LC_COLLATE__ : This variable determines the collation order used when sorting the results of pathname expansion, and determines the behavior of range expressions, equivalence classes, and collating sequences within pathname expansion and pattern matching. ;__LC_CTYPE__ : This variable determines the interpretation of characters and the behavior of character classes within pathname expansion and pattern matching. ;__LC_MESSAGES__ : This variable determines the locale used to translate double-quoted strings preceded by a __$__. ;__LC_NUMERIC__ : This variable determines the locale category used for number formatting. ;__LINES__ : Used by the __select__ builtin command to determine the column length for printing selection lists. Automatically set upon receipt of a SIGWINCH. ;__COLUMNS__ : Used by the __select__ builtin command to determine the terminal width when printing selection lists. Automatically set upon receipt of a SIGWINCH. ;__PROMPT_COMMAND__ : If set, the value is executed as a command prior to issuing each primary prompt. ;__IGNOREEOF__ : Controls the action of an interactive shell on receipt of an __EOF__ character as the sole input. If set, the value is the number of consecutive __EOF__ characters which must be typed as the first characters on an input line before __bash__ exits. If the variable exists but does not have a numeric value, or has no value, the default value is 10. If it does not exist, __EOF__ signifies the end of input to the shell. ;__TMOUT__ : If set to a value greater than zero, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt. __Bash__ terminates after waiting for that number of seconds if input does not arrive. ;__FCEDIT__ : The default editor for the __fc__ builtin command. ;__FIGNORE__ : A colon-separated list of suffixes to ignore when performing filename completion (see __READLINE__ below). A filename whose suffix matches one of the entries in __FIGNORE__ is excluded from the list of matched filenames. A sample value is ".o:~". ;__GLOBIGNORE__ : A colon-separated list of patterns defining the set of filenames to be ignored by pathname expansion. If a filename matched by a pathname expansion pattern also matches one of the patterns in __GLOBIGNORE__ , it is removed from the list of matches. ;__INPUTRC__ : The filename for the __readline__ startup file, overriding the default of ~/.inputrc (see __READLINE__ below). ;__HISTCONTROL__ : If set to a value of ''ignorespace'' , lines which begin with a __space__ character are not entered on the history list. If set to a value of ''ignoredups'' , lines matching the last history line are not entered. A value of ''ignoreboth'' combines the two options. If unset, or if set to any other value than those above, all lines read by the parser are saved on the history list, subject to the value of __HISTIGNORE__ . This variable's function is superseded by __HISTIGNORE__ . The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of __HISTCONTROL__ . ;__HISTIGNORE__ : A colon-separated list of patterns used to decide which command lines should be saved on the history list. Each pattern is anchored at the beginning of the line and must match the complete line (no implicit `__*__' is appended). Each pattern is tested against the line after the checks specified by __HISTCONTROL__ are applied. In addition to the normal shell pattern matching characters, `__&__' matches the previous history line. `__&__' may be escaped using a backslash; the backslash is removed before attempting a match. The second and subsequent lines of a multi-line compound command are not tested, and are added to the history regardless of the value of __HISTIGNORE__ . ;__histchars__ : The two or three characters which control history expansion and tokenization (see __HISTORY EXPANSION__ below). The first character is the ''history expansion'' character, the character which signals the start of a history expansion, normally `__!__'. The second character is the ''quick substitution'' character, which is used as shorthand for re-running the previous command entered, substituting one string for another in the command. The default is `__^__'. The optional third character is the character which indicates that the remainder of the line is a comment when found as the first character of a word, normally `__#__'. The history comment character causes history substitution to be skipped for the remaining words on the line. It does not necessarily cause the shell parser to treat the rest of the line as a comment. ;__HOSTFILE__ : Contains the name of a file in the same format as /etc/hosts that should be read when the shell needs to complete a hostname. The list of possible hostname completions may be changed while the shell is running; the next time hostname completion is attempted after the value is changed, __bash__ adds the contents of the new file to the existing list. If __HOSTFILE__ is set, but has no value, __bash__ attempts to read /etc/hosts to obtain the list of possible hostname completions. When __HOSTFILE__ is unset, the hostname list is cleared. ;__auto_resume__ : This variable controls how the shell interacts with the user and job control. If this variable is set, single word simple commands without redirections are treated as candidates for resumption of an existing stopped job. There is no ambiguity allowed; if there is more than one job beginning with the string typed, the job most recently accessed is selected. The ''name'' of a stopped job, in this context, is the command line used to start it. If set to the value ''exact'' , the string supplied must match the name of a stopped job exactly; if set to ''substring'' , the string supplied needs to match a substring of the name of a stopped job. The ''substring'' value provides functionality analogous to the __%?__ job identifier (see __JOB CONTROL__ below). If set to any other value, the supplied string must be a prefix of a stopped job's name; this provides functionality analogous to the __%__ job identifier. ;__COMPREPLY__ : An array variable from which __bash__ reads the possible completions generated by a shell function invoked by the programmable completion facility (see __Programmable Completion__ below). !Arrays __Bash__ provides one-dimensional array variables. Any variable may be used as an array; the __declare__ builtin will explicitly declare an array. There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Arrays are indexed using integers and are zero-based. An array is created automatically if any variable is assigned to using the syntax ''name''[[''subscript'']=''value''. The ''subscript'' is treated as an arithmetic expression that must evaluate to a number greater than or equal to zero. To explicitly declare an array, use __declare -a ''name''__ (see __SHELL BUILTIN COMMANDS__ below). __declare -a ''name''[[''subscript'']__ is also accepted; the ''subscript'' is ignored. Attributes may be specified for an array variable using the __declare__ and __readonly__ builtins. Each attribute applies to all members of an array. Arrays are assigned to using compound assignments of the form ''name''=__(__value''1'' ... value''n''__)__, where each ''value'' is of the form [[''subscript'']=''string''. Only ''string'' is required. If the optional brackets and subscript are supplied, that index is assigned to; otherwise the index of the element assigned is the last index assigned to by the statement plus one. Indexing starts at zero. This syntax is also accepted by the __declare__ builtin. Individual array elements may be assigned to using the ''name''[[''subscript'']=''value'' syntax introduced above. Any element of an array may be referenced using ${''name''[[''subscript'']}. The braces are required to avoid conflicts with pathname expansion. If ''subscript'' is __@__ or __*__, the word expands to all members of ''name''. These subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${''name''[[*]} expands to a single word with the value of each array member separated by the first character of the __IFS__ special variable, and ${''name''[[@]} expands each element of ''name'' to a separate word. When there are no array members, ${''name''[[@]} expands to nothing. This is analogous to the expansion of the special parameters __*__ and __@__ (see __Special Parameters__ above). ${#''name''[[''subscript'']} expands to the length of ${''name''[[''subscript'']}. If ''subscript'' is __*__ or __@__, the expansion is the number of elements in the array. Referencing an array variable without a subscript is equivalent to referencing element zero. The __unset__ builtin is used to destroy arrays. __unset__ ''name''[[''subscript''] destroys the array element at index ''subscript''. __unset__ ''name'', where ''name'' is an array, or __unset__ ''name''[[''subscript''], where ''subscript'' is __*__ or __@__, removes the entire array. The __declare__ , __local__ , and __readonly__ builtins each accept a __-a__ option to specify an array. The __read__ builtin accepts a __-a__ option to assign a list of words read from the standard input to an array. The __set__ and __declare__ builtins display array values in a way that allows them to be reused as assignments.
6 pages link to
bash(1)Part3
:
bash(1)Part7
bash(1)Part6
bash(1)Part4
bash(1)Part2
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.