BASH
From SkyWiki
(New page: == BASH command shell syntax == category:remember) |
Current revision (11:05, 15 September 2008) (view source) m (→set) |
||
(5 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
- | + | Bash manual page: [http://www.gnu.org/software/bash/manual/bashref.html HTML] [http://www.gnu.org/software/bash/manual/bashref.txt ASCII] | |
+ | |||
[[category:remember]] | [[category:remember]] | ||
+ | == BASH command shell syntax == | ||
+ | |||
+ | ===set=== | ||
+ | <code>set</code> print current environment variables | ||
+ | |||
+ | <code>export [set] <VARIABLE>=<VALUE></code> set environment variable | ||
+ | |||
+ | ===for=== | ||
+ | <code> | ||
+ | for name [in words ...]; do commands; done | ||
+ | </code> | ||
+ | Expand words, and execute commands once for each member in the resultant list, with name bound to the current member. If ‘in words’ is not present, the for command executes the commands once for each positional parameter that is set, as if ‘in "$@"’ had been specified (see Special Parameters). The return status is the exit status of the last command that executes. If there are no items in the expansion of words, no commands are executed, and the return status is zero. | ||
+ | |||
+ | also see [http://www.gnu.org/software/bash/manual/bashref.html#Looping-Constructs Looping Constructs] | ||
+ | |||
+ | ===if=== | ||
+ | <code> | ||
+ | if test-commands; then | ||
+ | consequent-commands; | ||
+ | [elif more-test-commands; then | ||
+ | more-consequents;] | ||
+ | [else alternate-consequents;] | ||
+ | fi | ||
+ | </code> | ||
+ | The test-commands list is executed, and if its return status is zero, the consequent-commands list is executed. If test-commands returns a non-zero status, each elif list is executed in turn, and if its exit status is zero, the corresponding more-consequents is executed and the command completes. If ‘else alternate-consequents’ is present, and the final command in the final if or elif clause has a non-zero exit status, then alternate-consequents is executed. The return status is the exit status of the last command executed, or zero if no condition tested true. | ||
+ | |||
+ | also see [http://www.gnu.org/software/bash/manual/bashref.html#Conditional-Constructs Conditional Constructs] | ||
+ | |||
+ | |||
+ | ===variable expansion=== | ||
+ | $? | ||
+ | Expands to the exit status of the most recently executed foreground pipeline. | ||
+ | |||
+ | $! | ||
+ | Expands to the process id of the most recently executed background (asynchronous) command. | ||
+ | |||
+ | also see [http://www.gnu.org/software/bash/manual/bashref.html#Special-Parameters Special Parameters] |
Current revision
Contents |
BASH command shell syntax
set
set
print current environment variables
export [set] <VARIABLE>=<VALUE>
set environment variable
for
for name [in words ...]; do commands; done
Expand words, and execute commands once for each member in the resultant list, with name bound to the current member. If ‘in words’ is not present, the for command executes the commands once for each positional parameter that is set, as if ‘in "$@"’ had been specified (see Special Parameters). The return status is the exit status of the last command that executes. If there are no items in the expansion of words, no commands are executed, and the return status is zero.
also see Looping Constructs
if
if test-commands; then consequent-commands; [elif more-test-commands; then more-consequents;] [else alternate-consequents;] fi
The test-commands list is executed, and if its return status is zero, the consequent-commands list is executed. If test-commands returns a non-zero status, each elif list is executed in turn, and if its exit status is zero, the corresponding more-consequents is executed and the command completes. If ‘else alternate-consequents’ is present, and the final command in the final if or elif clause has a non-zero exit status, then alternate-consequents is executed. The return status is the exit status of the last command executed, or zero if no condition tested true.
also see Conditional Constructs
variable expansion
$? Expands to the exit status of the most recently executed foreground pipeline.
$! Expands to the process id of the most recently executed background (asynchronous) command.
also see Special Parameters