Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
bash(1)Part5
Edit
PageHistory
Diff
Info
LikePages
!!BASH MAN PAGE (Part 5) __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 [bash(1)Part3] * PARAMETERS [bash(1)Part4] * EXPANSION __Part 5__ * __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 ---- !!REDIRECTION Before a command is executed, its input and output may be ''redirected'' using a special notation interpreted by the shell. Redirection may also be used to open and close files for the current shell execution environment. The following redirection operators may precede or appear anywhere within a ''simple command'' or may follow a ''command'' . Redirections are processed in the order they appear, from left to right. In the following descriptions, if the file descriptor number is omitted, and the first character of the redirection operator is __<__ , the redirection refers to the standard input (file descriptor 0). If the first character of the redirection operator is __>__ , the redirection refers to the standard output (file descriptor 1). The word following the redirection operator in the following descriptions, unless otherwise noted, is subjected to brace expansion, tilde expansion, parameter expansion, command substitution, arithmetic expansion, quote removal, pathname expansion, and word splitting. If it expands to more than one word, __bash__ reports an error. Note that the order of redirections is significant. For example, the command ls __>__ dirlist 2__>&__1 directs both standard output and standard error to the file ''dirlist'' , while the command ls 2__>&__1 __>__ dirlist directs only the standard output to file ''dirlist'' , because the standard error was duplicated as standard output before the standard output was redirected to ''dirlist'' . __Bash__ handles several filenames specially when they are used in redirections, as described in the following table: ;__/dev/fd/''fd''__ : If ''fd'' is a valid integer, file descriptor ''fd'' is duplicated. ;__/dev/stdin__ : File descriptor 0 is duplicated. ;__/dev/stdout__ : File descriptor 1 is duplicated. ;__/dev/stderr__ : File descriptor 2 is duplicated. ;__/dev/tcp/''host''/''port''__ : If ''host'' is a valid hostname or Internet address, and ''port'' is an integer port number, __bash__ attempts to open a TCP connection to the corresponding socket. ;__/dev/udp/''host''/''port''__ : If ''host'' is a valid hostname or Internet address, and ''port'' is an integer port number, __bash__ attempts to open a UDP connection to the corresponding socket. A failure to open or create a file causes the redirection to fail. !Redirecting Input Redirection of input causes the file whose name results from the expansion of ''word'' to be opened for reading on file descriptor ''n'' , or the standard input (file descriptor 0) if ''n'' is not specified. The general format for redirecting input is: [[''n'']__<__''word'' !Redirecting Output Redirection of output causes the file whose name results from the expansion of ''word'' to be opened for writing on file descriptor ''n'' , or the standard output (file descriptor 1) if ''n'' is not specified. If the file does not exist it is created; if it does exist it is truncated to zero size. The general format for redirecting output is: [[''n'']__>__''word'' If the redirection operator is __>__ , and the __noclobber__ option to the __set__ builtin has been enabled, the redirection will fail if the file whose name results from the expansion of ''word'' exists and is a regular file. If the redirection operator is __>|__ , or the redirection operator is __>__ and the __noclobber__ option to the __set__ builtin command is not enabled, the redirection is attempted even if the file named by ''word'' exists. !Appending Redirected Output Redirection of output in this fashion causes the file whose name results from the expansion of ''word'' to be opened for appending on file descriptor ''n'' , or the standard output (file descriptor 1) if ''n'' is not specified. If the file does not exist it is created. The general format for appending output is: [[''n'']__>>__''word'' !Redirecting Standard Output and Standard Error __Bash__ allows both the standard output (file descriptor 1) and the standard error output (file descriptor 2) to be redirected to the file whose name is the expansion of ''word'' with this construct. There are two formats for redirecting standard output and standard error: __&>__''word'' and __>&__''word'' Of the two forms, the first is preferred. This is semantically equivalent to __>__''word'' 2__>&__1 !Here Documents This type of redirection instructs the shell to read input from the current source until a line containing only ''word'' (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command. The format of here-documents is as follows: __<<__[[__-__]''word'' %%% ''here-document'' %%% ''delimiter'' %%% No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on ''word'' . If any characters in ''word'' are quoted, the ''delimiter'' is the result of quote removal on ''word'' , and the lines in the here-document are not expanded. If ''word'' is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion. In the latter case, the character sequence __\<newline>__ is ignored, and __\__ must be used to quote the characters __\__ , __$__ , and __`__ . If the redirection operator is __<<-__ , then all leading tab characters are stripped from input lines and the line containing ''delimiter'' . This allows here-documents within shell scripts to be indented in a natural fashion. !"Duplicating File Descriptors" The redirection operator [[''n'']__<&__''word'' is used to duplicate input file descriptors. If ''word'' expands to one or more digits, the file descriptor denoted by ''n'' is made to be a copy of that file descriptor. If the digits in ''word'' do not specify a file descriptor open for input, a redirection error occurs. If ''word'' evaluates to __-__ , file descriptor ''n'' is closed. If ''n'' is not specified, the standard input (file descriptor 0) is used. The operator [[''n'']__>&__''word'' is used similarly to duplicate output file descriptors. If ''n'' is not specified, the standard output (file descriptor 1) is used. If the digits in ''word'' do not specify a file descriptor open for output, a redirection error occurs. As a special case, if ''n'' is omitted, and ''word'' does not expand to one or more digits, the standard output and standard error are redirected as described previously. !"Opening File Descriptors for Reading and Writing" The redirection operator [[''n'']__<>__''word'' causes the file whose name is the expansion of ''word'' to be opened for both reading and writing on file descriptor ''n'' , or on file descriptor 0 if ''n'' is not specified. If the file does not exist, it is created. !!ALIASES ''Aliases'' allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the __alias__ and __unalias__ builtin commands (see __SHELL BUILTIN COMMANDS__ below). The first word of each command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias. The alias name and the replacement text may contain any valid shell input, including the ''metacharacters'' listed above, with the exception that the alias name may not contain ''=''. The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias __ls__ to __ls -F__ , for instance, and __bash__ does not try to recursively expand the replacement text. If the last character of the alias value is a ''blank'' , then the next command word following the alias is also checked for alias expansion. Aliases are created and listed with the __alias__ command, and removed with the __unalias__ command. There is no mechanism for using arguments in the replacement text. If arguments are needed, a shell function should be used (see __FUNCTIONS__ below). Aliases are not expanded when the shell is not interactive, unless the __expand_aliases__ shell option is set using __shopt__ (see the description of __shopt__ under __SHELL BUILTIN COMMANDS__ below). The rules concerning the definition and use of aliases are somewhat confusing. __Bash__ always reads at least one complete line of input before executing any of the commands on that line. Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read. The commands following the alias definition on that line are not affected by the new alias. This behavior is also an issue when functions are executed. Aliases are expanded when a function definition is read, not when the function is executed, because a function definition is itself a compound command. As a consequence, aliases defined in a function are not available until after that function is executed. To be safe, always put alias definitions on a separate line, and do not use __alias__ in compound commands. For almost every purpose, aliases are superseded by shell functions. !!FUNCTIONS A shell function, defined as described above under __SHELL GRAMMAR__ , stores a series of commands for later execution. When the name of a shell function is used as a simple command name, the list of commands associated with that function name is executed. Functions are executed in the context of the current shell; no new process is created to interpret them (contrast this with the execution of a shell script). When a function is executed, the arguments to the function become the positional parameters during its execution. The special parameter __#__ is updated to reflect the change. Positional parameter 0 is unchanged. The __FUNCNAME__ variable is set to the name of the function while the function is executing. All other aspects of the shell execution environment are identical between a function and its caller with the exception that the __DEBUG__ trap (see the description of the __trap__ builtin under __SHELL BUILTIN COMMANDS__ below) is not inherited. Variables local to the function may be declared with the __local__ builtin command. Ordinarily, variables and their values are shared between the function and its caller. If the builtin command __return__ is executed in a function, the function completes and execution resumes with the next command after the function call. When a function completes, the values of the positional parameters and the special parameter __#__ are restored to the values they had prior to the function's execution. Function names and definitions may be listed with the __-f__ option to the __declare__ or __typeset__ builtin commands. The __-F__ option to __declare__ or __typeset__ will list the function names only. Functions may be exported so that subshells automatically have them defined with the __-f__ option to the __export__ builtin. Functions may be recursive. No limit is imposed on the number of recursive calls. !!ARITHMETIC EVALUATION The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the __let__ builtin command and __Arithmetic Expansion__). Evaluation is done in long integers with no check for overflow, though division by 0 is trapped and flagged as an error. The operators and their precedence and associativity are the same as in the C language. The following list of operators is grouped into levels of equal-precedence operators. The levels are listed in order of decreasing precedence. ;__''id''++ ''id''-__ : variable post-increment and post-decrement ;__++''id'' -''id''__ : variable pre-increment and pre-decrement ;__- +__ : unary minus and plus ;__! ~__ : logical and bitwise negation ;__**__ : exponentiation ;__* / %__ : multiplication, division, remainder ;__+ -__ : addition, subtraction ;__<< >>__ : left and right bitwise shifts ;__<= >= < >__ : comparison ;__== !=__ : equality and inequality ;__&__ : bitwise AND ;__^__ : bitwise exclusive OR ;__|__ : bitwise OR ;__&&__ : logical AND ;__||__ : logical OR __''expr''?''expr'':''expr''__ ;: conditional evaluation ;__= *= /= %= += -= <<= >>= &= ^= |=__ : assignment ;__''expr1'' , ''expr2''__ : comma Shell variables are allowed as operands; parameter expansion is performed before the expression is evaluated. Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax. The value of a variable is evaluated as an arithmetic expression when it is referenced. A shell variable need not have its integer attribute turned on to be used in an expression. Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the form [[''base#'']n, where ''base'' is a decimal number between 2 and 64 representing the arithmetic base, and ''n'' is a number in that base. If ''base#'' is omitted, then base 10 is used. The digits greater than 9 are represented by the lowercase letters, the uppercase letters, _, and @, in that order. If ''base'' is less than or equal to 36, lowercase and uppercase letters may be used interchangably to represent numbers between 10 and 35. Operators are evaluated in order of precedence. Sub-expressions in parentheses are evaluated first and may override the precedence rules above. !!CONDITIONAL EXPRESSIONS Conditional expressions are used by the __[[[[__ compound command and the __test__ and __[[__ builtin commands to test file attributes and perform string and arithmetic comparisons. Expressions are formed from the following unary or binary primaries. If any ''file'' argument to one of the primaries is of the form ''/dev/fd/n'', then file descriptor ''n'' is checked. If the ''file'' argument to one of the primaries is one of ''/dev/stdin'', ''/dev/stdout'', or ''/dev/stderr'', file descriptor 0, 1, or 2, respectively, is checked. ;__-a ''file''__ : True if ''file'' exists. ;__-b ''file''__ : True if ''file'' exists and is a block special file. ;__-c ''file''__ : True if ''file'' exists and is a character special file. ;__-d ''file''__ : True if ''file'' exists and is a directory. ;__-e ''file''__ : True if ''file'' exists. ;__-f ''file''__ : True if ''file'' exists and is a regular file. ;__-g ''file''__ : True if ''file'' exists and is set-group-id. ;__-h ''file''__ : True if ''file'' exists and is a symbolic link. ;__-k ''file''__ : True if ''file'' exists and its "sticky" bit is set. ;__-p ''file''__ : True if ''file'' exists and is a named pipe (FIFO). ;__-r ''file''__ : True if ''file'' exists and is readable. ;__-s ''file''__ : True if ''file'' exists and has a size greater than zero. ;__-t ''fd''__ : True if file descriptor ''fd'' is open and refers to a terminal. ;__-u ''file''__ : True if ''file'' exists and its set-user-id bit is set. ;__-w ''file''__ : True if ''file'' exists and is writable. ;__-x ''file''__ : True if ''file'' exists and is executable. ;__-O ''file''__ : True if ''file'' exists and is owned by the effective user id. ;__-G ''file''__ : True if ''file'' exists and is owned by the effective group id. ;__-L ''file''__ : True if ''file'' exists and is a symbolic link. ;__-S ''file''__ : True if ''file'' exists and is a socket. ;__-N ''file''__ : True if ''file'' exists and has been modified since it was last read. ;''file1'' -__nt__ ''file2'' : True if ''file1'' is newer (according to modification date) than ''file2''. ;''file1'' -__ot__ ''file2'' : True if ''file1'' is older than ''file2''. ;''file1'' __-ef__ ''file2'' : True if ''file1'' and ''file2'' have the same device and inode numbers. ;__-o ''optname''__ : True if shell option ''optname'' is enabled. See the list of options under the description of the __-o__ option to the __set__ builtin below. ;__-z ''string''__ : True if the length of ''string'' is zero. ;__-n ''string''__ : ;''string'' : True if the length of ''string'' is non-zero. ;''string1'' __==__ ''string2'' : True if the strings are equal. __=__ may be used in place of __==__. ;''string1'' __!=__ ''string2'' : True if the strings are not equal. ;''string1'' __<__ ''string2'' : True if ''string1'' sorts before ''string2'' lexicographically in the current locale. ;''string1'' __>__ ''string2'' : True if ''string1'' sorts after ''string2'' lexicographically in the current locale. ;''''arg1'' __OP__ ''arg2'''' : __OP__ is one of __-eq__ , __-ne__ , __-lt__ , __-le__ , __-gt__ , or __-ge__ . These arithmetic binary operators return true if ''arg1'' is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to ''arg2'', respectively. ''Arg1'' and ''arg2'' may be positive or negative integers. !!SIMPLE COMMAND EXPANSION When a simple command is executed, the shell performs the following expansions, assignments, and redirections, from left to right. ;1.: The words that the parser has marked as variable assignments (those preceding the command name) and redirections are saved for later processing. ;2.: The words that are not variable assignments or redirections are expanded. If any words remain after expansion, the first word is taken to be the name of the command and the remaining words are the arguments. ;3.: Redirections are performed as described above under __REDIRECTION__ . ;4.: The text after the __=__ in each variable assignment undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before being assigned to the variable. If no command name results, the variable assignments affect the current shell environment. Otherwise, the variables are added to the environment of the executed command and do not affect the current shell environment. If any of the assignments attempts to assign a value to a readonly variable, an error occurs, and the command exits with a non-zero status. If no command name results, redirections are performed, but do not affect the current shell environment. A redirection error causes the command to exit with a non-zero status. If there is a command name left after expansion, execution proceeds as described below. Otherwise, the command exits. If one of the expansions contained a command substitution, the exit status of the command is the exit status of the last command substitution performed. If there were no command substitutions, the command exits with a status of zero. !!COMMAND EXECUTION After a command has been split into words, if it results in a simple command and an optional list of arguments, the following actions are taken. If the command name contains no slashes, the shell attempts to locate it. If there exists a shell function by that name, that function is invoked as described above in __FUNCTIONS__ . If the name does not match a function, the shell searches for it in the list of shell builtins. If a match is found, that builtin is invoked. If the name is neither a shell function nor a builtin, and contains no slashes, __bash__ searches each element of the __PATH__ for a directory containing an executable file by that name. __Bash__ uses a hash table to remember the full pathnames of executable files (see __hash__ under __SHELL BUILTIN COMMANDS__ below). A full search of the directories in __PATH__ is performed only if the command is not found in the hash table. If the search is unsuccessful, the shell prints an error message and returns an exit status of 127. If the search is successful, or if the command name contains one or more slashes, the shell executes the named program in a separate execution environment. Argument 0 is set to the name given, and the remaining arguments to the command are set to the arguments given, if any. If this execution fails because the file is not in executable format, and the file is not a directory, it is assumed to be a ''shell script'', a file containing shell commands. A subshell is spawned to execute it. This subshell reinitializes itself, so that the effect is as if a new shell had been invoked to handle the script, with the exception that the locations of commands remembered by the parent (see __hash__ below under __SHELL BUILTIN COMMANDS__) are retained by the child. If the program is a file beginning with __#!__ , the remainder of the first line specifies an interpreter for the program. The shell executes the specified interpreter on operating systems that do not handle this executable format themselves. The arguments to the interpreter consist of a single optional argument following the interpreter name on the first line of the program, followed by the name of the program, followed by the command arguments, if any. !!COMMAND EXECUTION ENVIRONMENT The shell has an ''execution environment'', which consists of the following: * open files inherited by the shell at invocation, as modified by redirections supplied to the __exec__ builtin * the current working directory as set by __cd__, __pushd__, or __popd__, or inherited by the shell at invocation * the file creation mode mask as set by __umask__ or inherited from the shell's parent * current traps set by __trap__ * shell parameters that are set by variable assignment or with __set__ or inherited from the shell's parent in the environment * shell functions defined during execution or inherited from the shell's parent in the environment * options enabled at invocation (either by default or with command-line arguments) or by __set__ * options enabled by __shopt__ * shell aliases defined with __alias__ * various process IDs, including those of background jobs, the value of __$$__, and the value of __$PPID__ When a simple command other than a builtin or shell function is to be executed, it is invoked in a separate execution environment that consists of the following. Unless otherwise noted, the values are inherited from the shell. * the shell's open files, plus any modifications and additions specified by redirections to the command * the current working directory * the file creation mode mask * shell variables marked for export, along with variables exported for the command, passed in the environment * traps caught by the shell are reset to the values the inherited from the shell's parent, and traps ignored by the shell are ignored A command invoked in this separate environment cannot affect the shell's execution environment. Command substitution and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except that traps caught by the shell are reset to the values that the shell inherited from its parent at invocation. Builtin commands that are invoked as part of a pipeline are also executed in a subshell environment. Changes made to the subshell environment cannot affect the shell's execution environment. !!ENVIRONMENT When a program is invoked it is given an array of strings called the ''environment'' . This is a list of ''name''-''value'' pairs, of the form ''name=value'' . The shell provides several ways to manipulate the environment. On invocation, the shell scans its own environment and creates a parameter for each name found, automatically marking it for ''export'' to child processes. Executed commands inherit the environment. The __export__ and __declare -x__ commands allow parameters and functions to be added to and deleted from the environment. If the value of a parameter in the environment is modified, the new value becomes part of the environment, replacing the old. The environment inherited by any executed command consists of the shell's initial environment, whose values may be modified in the shell, less any pairs removed by the __unset__ command, plus any additions via the __export__ and __declare -x__ commands. The environment for any ''simple command'' or function may be augmented temporarily by prefixing it with parameter assignments, as described above in __PARAMETERS__ . These assignment statements affect only the environment seen by that command. If the __-k__ option is set (see the __set__ builtin command below), then ''all'' parameter assignments are placed in the environment for a command, not just those that precede the command name. When __bash__ invokes an external command, the variable _____ is set to the full file name of the command and passed to that command in its environment. !!EXIT STATUS For the shell's purposes, a command which exits with a zero exit status has succeeded. An exit status of zero indicates success. A non-zero exit status indicates failure. When a command terminates on a fatal signal ''N'', __bash__ uses the value of 128+''N'' as the exit status. If a command is not found, the child process created to execute it returns a status of 127. If a command is found but is not executable, the return status is 126. If a command fails because of an error during expansion or redirection, the exit status is greater than zero. Shell builtin commands return a status of 0 (''true'') if successful, and non-zero (''false'') if an error occurs while they execute. All builtins return an exit status of 2 to indicate incorrect usage. __Bash__ itself returns the exit status of the last command executed, unless a syntax error occurs, in which case it exits with a non-zero value. See also the __exit__ builtin command below. !!SIGNALS When __bash__ is interactive, in the absence of any traps, it ignores __SIGTERM__ (so that __kill 0__ does not kill an interactive shell), and __SIGINT__ is caught and handled (so that the __wait__ builtin is interruptible). In all cases, __bash__ ignores [SIGQUIT]. If job control is in effect, __bash__ ignores [SIGTTIN], [SIGTTOU], and [SIGTSTP]. Synchronous jobs started by __bash__ have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchronous commands ignore [SIGINT] and [SIGQUIT] as well. Commands run as a result of command substitution ignore the keyboard-generated job control signals [SIGTTIN], [SIGTTOU], and [SIGTSTP]. The shell exits by default upon receipt of a [SIGHUP]. Before exiting, it resends the [SIGHUP] to all jobs, running or stopped. Stopped jobs are sent [SIGCONT] to ensure that they receive the [SIGHUP]. To prevent the shell from sending the signal to a particular job, it should be removed from the jobs table with the __disown__ builtin (see __SHELL BUILTIN COMMANDS__ below) or marked to not receive [SIGHUP] using __disown -h__ . If the __huponexit__ shell option has been set with __shopt__ , __bash__ sends a [SIGHUP] to all jobs when an interactive login shell exits. When __bash__ receives a signal for which a trap has been set while waiting for a command to complete, the trap will not be executed until the command completes. When __bash__ is waiting for an asynchronous command via the __wait__ builtin, the reception of a signal for which a trap has been set will cause the __wait__ builtin to return immediately with an exit status greater than 128, immediately after which the trap is executed. !!JOB CONTROL ''Job control'' refers to the ability to selectively stop (''suspend'') the execution of processes and continue (''resume'') their execution at a later point. A user typically employs this facility via an interactive interface supplied jointly by the system's terminal driver and __bash__ . The shell associates a ''job'' with each pipeline. It keeps a table of currently executing jobs, which may be listed with the __jobs__ command. When __bash__ starts a job asynchronously (in the ''background'' ), it prints a line that looks like: [[1] 25647 indicating that this job is job number 1 and that the process ID of the last process in the pipeline associated with this job is 25647. All of the processes in a single pipeline are members of the same job. __Bash__ uses the ''job'' abstraction as the basis for job control. To facilitate the implementation of the user interface to job control, the operating system maintains the notion of a ''current terminal process group ID. Members of this process group (processes whose process group ID is equal to the current terminal process group ID) receive keyboard-generated signals such as [SIGINT]. These processes are said to be in the ''foreground'' . ''Background'' processes are those whose process group ID differs from the terminal's; such processes are immune to keyboard-generated signals. Only foreground processes are allowed to read from or write to the terminal. Background processes which attempt to read from (write to) the terminal are sent a [SIGTTIN] ([SIGTTOU]) signal by the terminal driver, which, unless caught, suspends the process. If the operating system on which __bash__ is running supports job control, __bash__ contains facilities to use it. Typing the ''suspend'' character (typically __^Z__ , Control-Z) while a process is running causes that process to be stopped and returns control to __bash__ . Typing the ''delayed suspend'' character (typically __^Y__ , Control-Y) causes the process to be stopped when it attempts to read input from the terminal, and control to be returned to __bash__ . The user may then manipulate the state of this job, using the __bg__ command to continue it in the background, the __fg__ command to continue it in the foreground, or the __kill__ command to kill it. A __^Z__ takes effect immediately, and has the additional side effect of causing pending output and typeahead to be discarded. There are a number of ways to refer to a job in the shell. The character __%__ introduces a job name. Job number ''n'' may be referred to as __%n__ . A job may also be referred to using a prefix of the name used to start it, or using a substring that appears in its command line. For example, __%ce__ refers to a stopped __ce__ job. If a prefix matches more than one job, __bash__ reports an error. Using __%?ce__ , on the other hand, refers to any job containing the string __ce__ in its command line. If the substring matches more than one job, __bash__ reports an error. The symbols __%%__ and __%+__ refer to the shell's notion of the ''current job'' , which is the last job stopped while it was in the foreground or started in the background. The ''previous job'' may be referenced using __%-__ . In output pertaining to jobs (e.g., the output of the __jobs__ command), the current job is always flagged with a __+__ , and the previous job with a __-__ . Simply naming a job can be used to bring it into the foreground: __%1__ is a synonym for __"fg %1"__, bringing job 1 from the background into the foreground. Similarly, __%1 &__ resumes job 1 in the background, equivalent to __"bg %1"__. The shell learns immediately whenever a job changes state. Normally, __bash__ waits until it is about to print a prompt before reporting changes in a job's status so as to not interrupt any other output. If the __-b__ option to the __set__ builtin command is enabled, __bash__ reports such changes immediately. If an attempt to exit __bash__ is made while jobs are stopped, the shell prints a warning message. The __jobs__ command may then be used to inspect their status. If a second attempt to exit is made without an intervening command, the shell does not print another warning, and the stopped jobs are terminated. !!PROMPTING When executing interactively, __bash__ displays the primary prompt __PS1__ when it is ready to read a command, and the secondary prompt __PS2__ when it needs more input to complete a command. __Bash__ allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows: ;__\a__ : an ASCII bell character (07) ;__\d__ : the date in "Weekday Month Date" format (e.g., "Tue May 26") ;__\e__ : an ASCII escape character (033) ;__\h__ : the hostname up to the first `.' ;__\H__ : the hostname ;__\j__ : the number of jobs currently managed by the shell ;__\l__ : the basename of the shell's terminal device name ;__\n__ : newline ;__\r__ : carriage return ;__\s__ : the name of the shell, the basename of __$0__ (the portion following the final slash) ;__\t__ : the current time in 24-hour HH:MM:SS format ;__\T__ : the current time in 12-hour HH:MM:SS format ;__\@__ : the current time in 12-hour am/pm format ;__\u__ : the username of the current user ;__\v__ : the version of __bash__ (e.g., 2.00) ;__\V__ : the release of __bash__, version + patchlevel (e.g., 2.00.0) ;__\w__ : the current working directory ;__\W__ : the basename of the current working directory ;__\!__ : the history number of this command ;__\#__ : the command number of this command ;__\$__ : if the effective UID is 0, a __#__ , otherwise a __$__ ;__\''nnn''__ : the character corresponding to the octal number ''nnn'' ;__\\e__ : a backslash ;__\[[__ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt ;__\]__ : end a sequence of non-printing characters The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file (see __HISTORY__ below), while the command number is the position in the sequence of commands executed during the current shell session. After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and quote removal, subject to the value of the __promptvars__ shell option (see the description of the __shopt__ command under __SHELL BUILTIN COMMANDS__ below).
6 pages link to
bash(1)Part5
:
bash(1)Part7
bash(1)Part6
bash(1)Part4
bash(1)Part3
bash(1)Part2
bash(1)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.