This link has been bookmarked by 417 people . It was first bookmarked on 02 Apr 2006, by Santhosh.
-
07 Aug 18
-
20 Apr 18
-
16 Aug 17
-
11 Oct 16
-
26 May 16
-
19 May 16
-
IEEE POSIX Shell and Tools portion of the IEEE POSIX specification
-
Moreover, the shell allows control over the contents of commands’ environments.
-
The ‘$’ character introduces parameter expansion, command substitution, or arithmetic expansion
-
-
08 Jun 15
-
Process substitution
-
<(list)
-
input for list
-
the output of list
-
process substitution
-
command substitution
-
arithmetic expansion
-
parameter and variable expansion
-
-
17 May 15
-
12 Mar 15
-
10 Mar 15
-
A shell script is a text file containing shell commands
-
A shell script may be made executable by using the
chmodcommand
-
-
06 Feb 15
-
11 Nov 14
-
15 Sep 14
-
11 Aug 14
-
28 Jul 14
-
09 Jun 14
-
31 Mar 14
-
12 Feb 14
-
28 Jan 14
-
22 Oct 13
-
?Matches any single character.
-
-
03 Oct 13
-
13 Sep 13
-
14 Jun 13
-
01 Jun 13
-
Bash Reference Manual
-
-
04 Apr 13
-
21 Mar 13
Justin DesRosiersBash reference manual
bash reference shell unix manual scripting programming guide linux
-
08 Mar 13
-
03 Mar 13
-
23 Jan 13
-
If ‘|&’ is used, the standard error of command1 is connected to command2’s standard input through the pipe; it is shorthand for
2>&1 -
‘$’ character introduces parameter expansion, command substitution, or arithmetic expansion.
-
-
19 Jan 13
-
02 Dec 12
-
13 Nov 12
-
03 Nov 12
-
02 Nov 12
-
18 Oct 12
-
28 Sep 12
-
26 Jun 12
-
08 Mar 12
-
09 Feb 12
-
The order of expansions is: brace expansion, tilde expansion, parameter, variable, and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and filename expansion.
-
-
vikas pushkar"Tran"
-
02 Feb 12
-
17 Nov 11
-
09 Nov 11
-
28 Sep 11
-
27 Sep 11
-
22 Aug 11
-
3.1.1 Shell Operation
-
-
Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’.
-
- Simple Commands: The most common type of command.
- Pipelines: Connecting the input and output of several commands.
- Lists: How to execute commands sequentially.
- Compound Commands: Shell commands for control flow.
- Coprocesses: Two-way communication between commands.
-
[
time[-p]] [!] command1 [ [|or|&] command2 ...] -
If ‘|&’ is used, the standard error of command1 is connected to command2's standard input through the pipe; it is shorthand for
2>&1 |. This implicit redirection of the standard error is performed after any redirections specified by the command. -
The reserved word
timecauses timing statistics to be printed for the pipeline once it finishes. The statistics currently consist of elapsed (wall-clock) time and user and system time consumed by the command's execution. The -p option changes the output format to that specified by posix. The TIMEFORMAT variable may be set to a format string that specifies how the timing information should be displayed. -
If the pipeline is not executed asynchronously (see Lists), the shell waits for all commands in the pipeline to complete.
-
Each command in a pipeline is executed in its own subshell (see Command Execution Environment). The exit status of a pipeline is the exit status of the last command in the pipeline,
-
If the reserved word ‘!’ precedes the pipeline, the exit status is the logical negation of the exit status as described above.
-
3.2.3 Lists of Commands
-
If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell.
-
An and list has the form
command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.
An or list has the form
command1 || command2
command2 is executed if, and only if, command1 returns a non-zero exit status.
-
Compound commands are the shell programming constructs. Each construct begins with a reserved word or control operator and is terminated by a corresponding reserved word or operator. Any redirections (see Redirections) associated with a compound command apply to all commands within that compound command unless explicitly overridden.
Bash provides looping constructs, conditional commands, and mechanisms to group commands and execute them as a unit.
-
If ‘in words’ is not present, the
forcommand executes the commands once for each positional parameter that is set, as if ‘in "$@"’ had been specified -
Each clause must be terminated with ‘;;’, ‘;&’, or ‘;;&’. The word undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before matching is attempted. Each pattern undergoes tilde expansion, parameter expansion, command substitution, and arithmetic expansion.
-
An additional binary operator, ‘=~’, is available, with the same precedence as ‘==’ and ‘!=’. When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in regex3)). The return value is 0 if the string matches the pattern, and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression's return value is 2.
-
3.2.4.3 Grouping Commands
-
A function definition may be deleted using the -f option to the
unsetbuiltin -
When a function is executed, the arguments to the function become the positional parameters during its execution (see Positional Parameters). The special parameter ‘#’ that expands to the number of positional parameters is updated to reflect the change. Special parameter
0is unchanged. The first element of 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 these exceptions: the DEBUG and RETURN traps are not inherited unless the function has been given the
traceattribute using thedeclarebuiltin or the-o functraceoption has been enabled with thesetbuiltin, (in which case all functions inherit the DEBUG and RETURN traps), and the ERR trap is not inherited unless the-o errtraceshell option has been enabled. See Bourne Shell Builtins, for the description of thetrapbuiltin. -
Variables local to the function may be declared with the
localbuiltin. These variables are visible only to the function and the commands it invokes. -
Function names and definitions may be listed with the -f option to the
declareortypesetbuiltin commands (see Bash Builtins). The -F option todeclareortypesetwill list the function names only (and optionally the source file and line number, if theextdebugshell option is enabled). Functions may be exported so that subshells automatically have them defined with the -f option to theexportbuiltin (see Bourne Shell Builtins). Note that shell functions and variables with the same name may result in multiple identically-named entries in the environment passed to the shell's children. Care should be taken in cases where this may cause a problem. -
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 thesetbuiltin command. Positional parameterNmay be referenced as${N}, or as$NwhenNconsists of a single digit. Positional parameters may not be assigned to with assignment statements. Thesetandshiftbuiltins are used to set and unset them (see Shell Builtin Commands). The positional parameters are temporarily replaced when a shell function is executed (see Shell Functions).When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces.
-
A parameter is an entity that stores values. It can be a
name, a number, or one of the special characters listed below. A variable is a parameter denoted by aname. A variable has a value and zero or more attributes. Attributes are assigned using thedeclarebuiltin command (see the description of thedeclarebuiltin in Bash Builtins). -
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
unsetbuiltin command. -
The order of expansions is: brace expansion, tilde expansion, parameter, variable, and arithmetic expansion and command substitution (done in a left-to-right fashion), word splitting, and filename expansion.
-
xpansion and command substitution.
Only brace expansion, word splitting, and filename expansion can change the number of words of the expansion; other expansions expand a single word to a single word. The only exceptions to this are the expansions of
"$@"(see Special Parameters) and"${name[@]}"(see Arrays).After all expansions,
quote removal(see Quote Removal) is performed. -
Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For example,
bash$ echo a{d,c,b}e ade ace abeA sequence expression takes the form
{x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. -
-
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 HOME shell variable.
-
If the tilde-prefix is ‘~+’, the value of the shell variable PWD replaces the tilde-prefix. If the tilde-prefix is ‘~-’, the value of the shell variable OLDPWD, if it is set, is substituted.
-
~- The value of
$HOME~/foo- $HOME/foo
~fred/foo- The subdirectory
fooof the home directory of the userfred~+/foo- $PWD/foo
~-/foo- ${OLDPWD-'~-'}/foo
~N- The string that would be displayed by ‘dirs +N’
~+N- The string that would be displayed by ‘dirs +N’
~-N- The string that would be displayed by ‘dirs -N’
-
3.5.3 Shell Parameter Expansion
-
The basic form of parameter expansion is ${parameter}. The value of parameter is substituted. The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character that is not to be interpreted as part of its name.
-
The command substitution
$(catfile)can be replaced by the equivalent but faster$(<file). -
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
-
After word splitting, unless the -f option has been set (see The Set Builtin), Bash scans each word for the characters ‘*’, ‘?’, and ‘[’. 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.
-
When a pattern is used for filename expansion, the character ‘.’ at the start of a filename or immediately following a slash must be matched explicitly, unless the shell option
dotglobis set. When matching a file name, the slash character must always be matched explicitly. In other cases, the ‘.’ character is not treated specially. -
Pattern Matching
-
*- Matches any string, including the null string. When the
globstarshell option is enabled, and ‘*’ is used in a filename expansion context, two adjacent ‘*’s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a ‘/’, two adjacent ‘*’s will match only directories and subdirectories.?- Matches any single character.
-
Matches any one of the enclosed characters. A pair of characters separated by a hyphen denotes a range expression; any character that sorts between those two characters, inclusive, using the current locale's collating sequence and character set, is matched. If the first character following the ‘[’ is a ‘!’ or a ‘^’ then any character not enclosed is matched. 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
[:class:], where class is one of the following classes defined in the posix standard:alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
-
After the preceding expansions, all unquoted occurrences of the characters ‘\’, ‘'’, and ‘"’ that did not result from one of the above expansions are removed.
-
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.
-
Note that the order of redirections is significant. For example, the command
ls > dirlist 2>&1
directs both standard output (file descriptor 1) and standard error (file descriptor 2) to the file dirlist, while the command
ls 2>&1 > dirlist
-
If the redirection operator is ‘>|’, or the redirection operator is ‘>’ and the
noclobberoption is not enabled, the redirection is attempted even if the file named by word exists. -
The general format for appending output is:
[n]>>word
-
3.6.4 Redirecting Standard Output and Standard Error
This construct 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.
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
-
This is semantically equivalent to
>>word 2>&1
-
No parameter expansion, command substitution, arithmetic expansion, or filename 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
ewlineis ignored, and ‘\’ must be used to quote the characters ‘\’, ‘$’, and ‘`’.
-
-
18 Aug 11
-
05 Aug 11
-
06 Jun 11
-
01 Jun 11
-
31 May 11
-
17 May 11
-
25 Mar 11
-
08 Mar 11
-
23 Feb 11
-
22 Feb 11
-
19 Feb 11
-
18 Feb 11
-
25 Jan 11
-
18 Jan 11
-
15 Jan 11
-
08 Dec 10
Guy FawkesThis text is a brief description of the features that are present in the Bash shell
-
04 Dec 10
-
03 Dec 10
-
25 Nov 10
-
11 Nov 10
-
29 Oct 10
-
28 Oct 10
-
06 Oct 10
-
21 Sep 10
-
22 Aug 10
-
02 Aug 10
-
20 Jun 10
-
15 Jun 10
-
05 Jun 10
-
27 May 10
-
30 Apr 10
-
22 Mar 10
-
02 Feb 10
-
uilding blocks': commands, contro
-
or words to the shell. Quoting can be used to d
-
treatment for special chara
-
-
26 Jan 10
-
14 Jan 10
-
21 Dec 09
-
23 Nov 09
-
29 Sep 09
-
22 Sep 09
-
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.
-
-
17 Sep 09
-
14 Sep 09
-
12 Sep 09
-
25 Aug 09
-
22 Aug 09
-
14 Aug 09
-
02 Jul 09
-
-
Positional parameters are assigned from the shell's arguments when it is invoked
-
-
16 Apr 09
-
06 Apr 09
-
25 Mar 09
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.