Install Ubuntu Fedora and SUSE as Windows Apps!

 

Your Red Hat account gives you access to your profile, preferences, and services, depending on your status. Register. If you are a new customer, register now for access to product evaluations and purchasing capabilities. Red Hat Enterprise Linux 6. Introduction to SystemTap.

The optional p is a digit specifying the precision , the number of fractional digits after a decimal point. By default, the line editing commands are similar to those of emacs. However, when -f option is specified, suspend command can suspend even login shell. Any other key sequence bound to a readline command will terminate the search and execute that command.

Assumptions and Scope

SYSTEMTIME equivalent for linux. Ask Question. up vote 0 down vote favorite. I am doing cross-platform compilation of a huge solution written in C++ from VS to linux environment. My question is: what is the closest equivalent of struct SYSTEMTIME in linux?

There seems to be a dearth of information about the System. It's really nothing mysterious, and in the scheme of things, it's really not that important.

But a lack of documentation makes it shady. It's like an earlobe; we all have one, but nobody really knows why. This is a little web page I cooked up that explains the why. I'm going to assume you "go with the flow" and have a fairly typical system.

Some of the stuff on oopses comes from Alessandro Rubini's "Linux Device Drivers" which is where I learned most of what I know about kernel programming.

In the context of programming, a symbol is the building block of a program: It should be of no surprise that the kernel has symbols, just like the programs you write. The difference is, of course, that the kernel is a very complicated piece of coding and has many, many global symbols.

The kernel doesn't use symbol names like BytesRead. It's much happier knowing a variable or function name by the variable or function's address, like cf Humans, on the other hand, do not appreciate addresses like cf We prefer to use symbol names like BytesRead.

Normally, this doesn't present much of a problem. There are situations, however, where we need to know the address of a symbol or the symbol for an address. This is done by a symbol table, and is very similar to how gdb can give you the function name from an address or an address from a function name. A symbol table is a listing of all symbols along with their address.

Here is an example of a symbol table:. Actually, it's not really a disk file; it's a representation of kernel data which is given the illusion of being a disk file. Therefore, it will always be correct for the kernel that is currently running. When you compile a new kernel, your old System. What is the most common bug in the Linux kernel? Except here, the notion of a segfault is much more complicated and can be, as you can imagine, much more serious.

When the kernel dereferences an invalid pointer, it's not called a segfault -- it's called an "oops". An oops indicates a kernel bug and should always be reported and fixed. Note that an oops is not the same thing as a segfault. Your program usually cannot recover from a segfault. The kernel doesn't necessarily have to be in an unstable state when an oops occurs.

The Linux kernel is very robust; the oops may just kill the current process and leave the rest of the kernel in a good, solid state. An oops is not a kernel panic. In a panic, the kernel cannot continue; the system grinds to a halt and must be restarted.

An oops may cause a panic if a vital part of the system is destroyed. An oops in a device driver, for example, will almost never cause a panic.

When an oops occurs, the system will print out information that is relevent to debugging the problem, like the contents of all the CPU registers, and the location of page descriptor tables.

In particular, the contents of the EIP instruction pointer is printed. Since a kernel symbol doesn't have a fixed address until after the kernel is booted, cb can point to any kernel symbol. Kernel developers wouldn't have the faintest clue where to begin looking for the bug if you simply reported an address. They need a symbol name to begin hunting for the bug. To help understand cryptic oops output, a daemon called klogd , the kernel logging daemon, is used to perform symbol-address translation.

When an ooops occurs, klogd intercepts the oops report, translates addresses into symbol names e. The element with index 0 is the name of any currently-executing shell function. The bottom-most element is "main". This variable exists only when a shell function is executing. The default is system-dependent. 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. PWD The current working directory as set by the cd command. 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 this variable is in the environment when bash starts up, each shell option in the list will be enabled before reading any startup files.

The following variables are used by the shell. In some cases, bash assigns a default value to a variable; these cases are noted below. PATH is not used to search for the resultant file name.

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 ".: EMACS If bash finds this variable in the environment when the shell starts with value t , it assumes that the shell is running in an emacs shell buffer and disables line editing.

A sample value is ". If the list of values includes ignorespace , lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching the previous history entry to not be saved. A value of ignoreboth is shorthand for ignorespace and ignoredups. A value of erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If unset, the command history is not saved when an interactive shell exits.

When this variable is assigned a value, the history file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is The history file is also truncated to this size after writing it when an interactive shell exits.

If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions. 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.

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. IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command.

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 If it does not exist, EOF signifies the end of input to the shell.

LINES Used by the select builtin command to determine the column length for printing selection lists. 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.

PATH The search path for commands. A zero-length null directory name in the value of PATH indicates the current directory. A null directory name may appear as two adjacent colons, or as an initial or trailing colon.

The default path is system-dependent, and is set by the administrator who installs bash. If it is set while the shell is running, bash enables posix mode , as if the command set -o posix had been executed. PS2 The value of this parameter is expanded as with PS1 and used as the secondary prompt string. 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 escape sequences and their meanings are as follows; the braces denote optional portions. 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. The value of p determines whether or not the fraction is included. If the value is null, no timing information is displayed. A trailing newline is added when the format string is displayed. The select command terminates if input does not arrive after TMOUT seconds when input is coming from a terminal. In an interactive shell, 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. 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 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 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.

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.

The subscript is treated as an arithmetic expression that must evaluate to a number greater than or equal to zero. Attributes may be specified for an array variable using the declare and readonly builtins. Each attribute applies to all members of an array. 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.

The braces are required to avoid conflicts with pathname expansion. These subscripts differ only when the word appears within double quotes. Referencing an array variable without a subscript is equivalent to referencing element zero. The unset builtin is used to destroy arrays. Care must be taken to avoid unwanted side effects caused by filename generation.

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.

There are seven kinds of expansion performed: The order of expansions is: On systems that can support it, there is an additional expansion available: Only brace expansion, word splitting, and pathname expansion can change the number of words of the expansion; other expansions expand a single word to a single word.

Brace Expansion Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion , but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional preamble , followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.

The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right. Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. When integers are supplied, the expression expands to each number between x and y , inclusive.

When characters are supplied, the expression expands to each character lexicographically between x and y , inclusive. Note that both x and y must be of the same type. Brace expansion is performed before any other expansions, and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces. A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression.

Any incorrectly formed brace expansion is left unchanged. This construct is typically used as shorthand when the common prefix of the strings to be generated is longer than in the above example: Bash removes braces from words as a consequence of brace expansion. The same word is output as file1 file2 after expansion by bash. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible login name.

If this login name is the null string, the tilde is replaced with the value of the shell parameter HOME. If HOME is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name. If the login name is invalid, or the tilde expansion fails, the word is unchanged.

Each variable assignment is checked for unquoted tilde-prefixes immediately following a: In these cases, tilde expansion is also performed. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.

The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character which is not to be interpreted as part of its name.

If the first character of parameter is an exclamation point, a level of variable indirection is introduced. Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself.

This is known as indirect expansion. The exclamation point must immediately follow the left brace in order to introduce indirection. In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.

When not performing substring expansion, bash tests for a parameter that is unset or null; omitting the colon results in a test only for a parameter that is unset. If parameter is unset or null, the expansion of word is substituted. Otherwise, the value of parameter is substituted. If parameter is unset or null, the expansion of word is assigned to parameter.

The value of parameter is then substituted. Positional parameters and special parameters may not be assigned to in this way. If parameter is null or unset, the expansion of word or a message to that effect if word is not present is written to the standard error and the shell, if it is not interactive, exits.

If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted. Expands to up to length characters of parameter starting at the character specified by offset. If length is omitted, expands to the substring of parameter starting at the character specified by offset.

If offset evaluates to a number less than zero, the value is used as an offset from the end of the value of parameter. If parameter is , the result is length positional parameters beginning at offset.

A negative offset is taken relative to one greater than the maximum index of the specified array. Note that a negative offset must be separated from the colon by at least one space to avoid being confused with the: Substring indexing is zero-based unless the positional parameters are used, in which case the indexing starts at 1.

If name is not an array, expands to 0 if name is set and null otherwise. When is used and the expansion appears within double quotes, each key expands to a separate word. Parameter is expanded and the longest match of pattern against its value is replaced with string.

Normally only the first match is replaced. If pattern begins with , it must match at the beginning of the expanded value of parameter. Command Substitution Command substitution allows the output of a command to replace the command name. There are two forms: Embedded newlines are not deleted, but they may be removed during word splitting. The first backquote not preceded by a backslash terminates the command substitution.

Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes. If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results. Arithmetic Expansion Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of the result. The format for arithmetic expansion is: All tokens in the expression undergo parameter expansion, string expansion, command substitution, and quote removal.

Arithmetic expansions may be nested. If expression is invalid, bash prints a message indicating failure and no substitution occurs. The name of this file is passed as an argument to the current command as the result of the expansion. When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion. Word Splitting The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.

The shell treats each character of IFS as a delimiter, and splits the results of the other expansions into words on these characters. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS an IFS whitespace character.

A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs. Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed. If a parameter with no value is expanded within double quotes, a null argument results and is retained.

Note that if no expansion occurs, no splitting is performed. If one of these characters appears, then the word is regarded as a pattern , and replaced with an alphabetically sorted list of file names matching the pattern.

If no matching file names are found, and the shell option nullglob is disabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed.

If the failglob shell option is set, and no matches are found, an error message is printed and the command is not executed. If the shell option nocaseglob is enabled, the match is performed without regard to the case of alphabetic characters. When matching a pathname, the slash character must always be matched explicitly. Pattern Matching Any character that appears in a pattern, other than the special pattern characters described below, matches itself. The NUL character may not occur in a pattern.

A backslash escapes the following character; the escaping backslash is discarded when matching. The special pattern characters must be quoted if they are to be matched literally. The special pattern characters have the following meanings: Matches any single character.

If the first character following the [ is a! A - may be matched by including it as the first or last character in the set. A ] may be matched by including it as the first character in the set. Within [ and ] , character classes can be specified using the syntax [: Within [ and ] , the syntax [.

If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a. Composite patterns may be formed using one or more of the following sub-patterns: 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. 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. Bash handles several filenames specially when they are used in redirections, as described in the following table: A failure to open or create a file causes the redirection to fail.

Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally.

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: 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: 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: There are two formats for redirecting standard output and standard error: 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: 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. This allows here-documents within shell scripts to be indented in a natural fashion. Here Strings A variant of here documents, the format is: 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. 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.

If the file does not exist, it is created. The first word of each simple 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 replacement text may contain any valid shell input, including shell metacharacters.

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. 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. 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. Special parameter 0 is unchanged.

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. 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 and optionally the source file and line number, if the extdebug shell option is enabled.

Functions may be exported so that subshells automatically have them defined with the -f option to the export builtin. A function definition may be deleted using the -f option to the unset builtin. Care should be taken in cases where this may cause a problem. Functions may be recursive. No limit is imposed on the number of recursive calls. Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error. The operators and their precedence, associativity, and values 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. Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax. A shell variable that is null or unset evaluates to 0 when referenced by name without using the parameter expansion syntax. The value of a variable is evaluated as an arithmetic expression when it is referenced, or when a variable which has been given the integer attribute using declare -i is assigned a value.

A null value evaluates to 0. 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.

If base is less than or equal to 36, lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and Operators are evaluated in order of precedence.

Sub-expressions in parentheses are evaluated first and may override the precedence rules above. Expressions are formed from the following unary or binary primaries. Unless otherwise specified, primaries that operate on files follow symbolic links and operate on the target of the link, rather than the link itself.

Tag Description -a file True if file exists. See the list of options under the description of the -o option to the set builtin below. 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. The words that the parser has marked as variable assignments those preceding the command name and redirections are saved for later processing.

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. 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. If the command name contains no slashes, the shell attempts to locate it.

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.

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 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. If the program is a file beginning with! 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. Unless otherwise noted, the values are inherited from the shell. Command substitution, commands grouped with parentheses, 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. Otherwise, the invoked command inherits the file descriptors of the calling shell as modified by redirections.

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. 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.

An exit status of zero indicates success. A non-zero exit status indicates failure. If a command is not found, the child process created to execute it returns a status of If a command is found but is not executable, the return status is 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. Non-builtin commands run by bash have signal handlers set to the values inherited by the shell from its parent. If the huponexit shell option has been set with shopt , bash sends a SIGHUP to all jobs when an interactive login shell exits.

If bash is waiting for a command to complete and receives a signal for which a trap has been set, 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 , immediately after which the trap is executed.

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: 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.

These processes are said to be in the foreground. Only foreground processes are allowed to read from or write to the terminal. If the operating system on which bash is running supports job control, bash contains facilities to use it. 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.

There are a number of ways to refer to a job in the shell. 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. If a prefix matches more than one job, bash reports an error. If the substring matches more than one job, bash reports an error. In output pertaining to jobs e. Simply naming a job can be used to bring it into the foreground: The shell learns immediately whenever a job changes state.

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. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows: By default, the line editing commands are similar to those of emacs.

A vi-style line editing interface is also available. Readline Notation In this section, the emacs-style notation is used to denote keystrokes. Control keys are denoted by C- key , e. Similarly, meta keys are denoted by M- key , so M-x means Meta-X. On keyboards without a meta key, M- x means ESC x , i.

This makes ESC the meta prefix. Readline commands may be given numeric arguments , which normally act as a repeat count. Sometimes, however, it is the sign of the argument that is significant.

Passing a negative argument to a command that acts in the forward direction e. Commands whose behavior with arguments deviates from this are noted below. When a command is described as killing text, the text deleted is saved for possible future retrieval yanking. The killed text is saved in a kill ring. Consecutive kills cause the text to be accumulated into one unit, which can be yanked all at once. Commands which do not kill text separate the chunks of text on the kill ring.

Readline Initialization Readline is customized by putting commands in an initialization file the inputrc file. When a program which uses the readline library starts up, the initialization file is read, and the key bindings and variables are set.

There are only a few basic constructs allowed in the readline initialization file. Blank lines are ignored. Lines beginning with a are comments. Other lines denote key bindings and variable settings. The default key-bindings may be changed with an inputrc file. Other programs that use this library may add their own commands and bindings. For example, placing M-Control-u: The following symbolic character names are recognized: In addition to command names, readline allows keys to be bound to a string that is inserted when the key is pressed a macro.

Readline Key Bindings The syntax for controlling key bindings in the inputrc file is simple. All that is required is the name of the command or the text of a macro and a key sequence to which it should be bound.

The name may be specified in one of two ways: When using the form keyname: In the second form, "keyseq": Some GNU Emacs style key escapes can be used, as in the following example, but the symbolic character names are not recognized. Unquoted text is assumed to be a function name. In the macro body, the backslash escapes described above are expanded.

Bash allows the current readline key bindings to be displayed or modified with the bind builtin command. Readline Variables Readline has variables that can be used to further customize its behavior. A variable may be set in the inputrc file with a statement of the form set variable-name value Except where noted, readline variables can take the values On or Off without regard to case. Unrecognized variable names are ignored. When a variable value is read, empty or null values, "on" case-insensitive , and "1" are equivalent to On.

All other values are equivalent to Off. The variables and their default values are: If set to none , readline never rings the bell. If set to visible , readline uses a visible bell if one is available. This command is bound to M- in emacs mode and to in vi command mode. It may be set to any integer value greater than or equal to zero. If the number of possible completions is greater than or equal to the value of this variable, the user is asked whether or not he wishes to view them; otherwise they are simply listed on the terminal.

Completion characters will be inserted into the line as if they had been mapped to self-insert. Some systems need this to enable the arrow keys. The name meta-flag is a synonym for this variable. If this variable has not been given a value, the characters ESC and C-J will terminate an incremental search. The set of valid keymap names is emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-command , and vi-insert.

The default value is emacs ; the value of editing-mode also affects the default keymap. If set to on , words which have more than one possible completion cause the matches to be listed immediately instead of ringing the bell. Readline Conditional Constructs Readline implements a facility similar in spirit to the conditional compilation features of the C preprocessor which allows key bindings and variable settings to be performed as the result of tests.

There are four parser directives used. The text of the test extends to the end of the line; no characters are required to isolate it.

This may be used in conjunction with the set keymap command, for instance, to set bindings in the emacs-standard and emacs-ctlx keymaps only if readline is starting out in emacs mode.

This allows sun to match both sun and sun-cmd , for instance. Each program using the readline library sets the application name , and an initialization file can test for a particular value. This could be used to bind key sequences to functions useful for a specific program. For instance, the following command adds a key sequence that quotes the current or previous word in Bash: There are two search modes: Incremental searches begin before the user has finished typing the search string.

As each character of the search string is typed, readline displays the next entry from the history matching the string typed so far. An incremental search requires only as many characters as needed to find the desired history entry. The characters present in the value of the isearch-terminators variable are used to terminate an incremental search. If that variable has not been assigned a value the Escape and Control-J characters will terminate an incremental search.

Control-G will abort an incremental search and restore the original line. When the search is terminated, the history entry containing the search string becomes the current line. To find other matching entries in the history list, type Control-S or Control-R as appropriate. This will search backward or forward in the history for the next entry matching the search string typed so far.

Any other key sequence bound to a readline command will terminate the search and execute that command. For instance, a newline will terminate the search and accept the line, thereby executing the command from the history list. Readline remembers the last incremental search string. If two Control-Rs are typed without any intervening characters defining a new search string, any remembered search string is used. Non-incremental searches read the entire search string before starting to search for matching history lines.

The search string may be typed by the user or be part of the contents of the current line. Readline Command Names The following is a list of the names of the commands and the default key sequences to which they are bound. Command names without an accompanying key sequence are unbound by default.

In the following descriptions, point refers to the current cursor position, and mark refers to a cursor position saved by the set-mark command. The text between the point and mark is referred to as the region. Words are composed of alphanumeric characters letters and digits. With an argument, refresh the current line without clearing the screen.

If the line is a modified history line, then restore the history line to its original state. This is an incremental search. This is a non-incremental search.

With an argument n , insert the n th word from the previous command the words in the previous command begin with word 0. A negative argument inserts the n th word from the end of the previous command. Once the argument n is computed, the argument is extracted as if the "! With an argument, behave exactly like yank-nth-arg. Successive calls to yank-last-arg move back through the history list, inserting the last argument of each line in turn.

The history expansion facilities are used to extract the last argument, as if the "! This performs alias and history expansion as well as all of the shell word expansions. Any argument is ignored. If point is at the beginning of the line, there are no characters in the line, and the last character typed was not bound to delete-char , then return EOF.

When given a numeric argument, save the deleted text on the kill ring. This is how to insert characters like C-q , for example. Insert the character typed. If point is at the end of the line, then this transposes the two characters before point. Negative arguments have no effect. If point is at the end of the line, this transposes the last two words on the line.

With a negative argument, uppercase the previous word, but do not move point. With a negative argument, lowercase the previous word, but do not move point. With a negative argument, capitalize the previous word, but do not move point. With an explicit positive numeric argument, switches to overwrite mode. With an explicit non-positive numeric argument, switches to insert mode. This command affects only emacs mode; vi mode does overwrite differently.

Each call to readline starts in insert mode. In overwrite mode, characters bound to self-insert replace the text at point rather than pushing the text to the right. Characters bound to backward-delete-char replace the character before point with a space.

By default, this command is unbound. The killed text is saved on the kill-ring. Word boundaries are the same as those used by forward-word. Word boundaries are the same as those used by backward-word. The word boundaries are the same as backward-word. The word boundaries are the same as forward-word. Only works following yank or yank-pop.

M-- starts a negative argument. If this command is followed by one or more digits, optionally with a leading minus sign, those digits define the argument. If the command is followed by digits, executing universal-argument again ends the numeric argument, but is otherwise ignored. As a special case, if this command is immediately followed by a character that is neither a digit or minus sign, the argument count for the next command is multiplied by four. The argument count is initially one, so executing this function the first time makes the argument count four, a second time makes the argument count sixteen, and so on.

If none of these produces a match, filename completion is attempted. List the possible completions of the text before point. Repeated execution of menu-complete steps through the list of possible completions, inserting each match in turn.

At the end of the list of completions, the bell is rung subject to the setting of bell-style and the original text is restored. An argument of n moves n positions forward in the list of matches; a negative argument may be used to move backward through the list.

This command is intended to be bound to TAB , but is unbound by default. If at the end of the line, behaves identically to possible-completions. This command is unbound by default. Attempt completion on the text before point, treating it as a command name. Command completion attempts to match the text against aliases, reserved words, shell functions, shell builtins, and finally executable filenames, in that order.

List the possible completions of the text before point, treating it as a command name. If the metafied character x is lowercase, run the command that is bound to the corresponding uppercase character. ESC f is equivalent to Meta-f. This is like executing the undo command enough times to return the line to its initial state. If a numeric argument is supplied, the mark is set to that position.

The current cursor position is set to the saved position, and the old cursor position is saved as the mark. A negative count searches for previous occurrences. A negative count searches for subsequent occurrences. If a numeric argument is supplied, this command acts as a toggle: In either case, the line is accepted as if a newline had been typed. The default value of comment-begin causes this command to make the current line a shell comment.

If a numeric argument causes the comment character to be removed, the line will be executed by the shell. This pattern is used to generate a list of matching file names for possible completions. If a numeric argument is supplied, an asterisk is appended before pathname expansion.

If a numeric argument is supplied, the output is formatted in such a way that it can be made part of an inputrc file. First, the command name is identified. If a compspec has been defined for that command, the compspec is used to generate the list of possible completions for the word. If the command word is a full pathname, a compspec for the full pathname is searched for first. If no compspec is found for the full pathname, an attempt is made to find a compspec for the portion following the final slash.

Once a compspec has been found, it is used to generate the list of matching words. If a compspec is not found, the default bash completion as described above under Completing is performed. First, the actions specified by the compspec are used. Only matches which are prefixed by the word being completed are returned. Any completions specified by a filename expansion pattern to the -G option are generated next. The words generated by the pattern need not match the word being completed.

Next, the string specified as the argument to the -W option is considered. The string is first split using the characters in the IFS special variable as delimiters. Shell quoting is honored. Each word is then expanded using brace expansion, tilde expansion, parameter and variable expansion, command substitution, and arithmetic expansion, as described above under EXPANSION. The results are split using the rules described above under Word Splitting. The results of the expansion are prefix-matched against the word being completed, and the matching words become the possible completions.