| ||||||
|
|
Go to the next chapter. Bash contains features that appear in other popular shells, and some features that only appear in Bash. Some of the shells that Bash has borrowed concepts from are the Bourne Shell (sh), the Korn Shell (ksh), and the C-shell (csh and its successor, tcsh). The following menu breaks the features up into categories based upon which one of these other shells inspired the feature. This manual is meant as a brief introduction to features found in Bash. The Bash manual page should be used as the definitive reference on shell behavior.
Bourne Shell Style FeaturesBash is an acronym for Bourne Again SHell. The Bourne shell is the traditional Unix shell originally written by Stephen Bourne. All of the Bourne shell builtin commands are available in Bash, and the rules for evaluation and quoting are taken from the Posix 1003.2 specification for the `standard' Unix shell. This section briefly summarizes things which Bash inherits from the Bourne shell: shell control structures, builtins, variables, and other features. It also lists the significant differences between Bash and the Bourne Shell.
Looping ConstructsNote that wherever you see a ; in the description of a command's syntax, it may be replaced indiscriminately with one or more newlines. Bash supports the following looping constructs. until The syntax of the until test-commands; do consequent-commands; done Execute consequent-commands as long as the final command in test-commands has an exit status which is not zero. while The syntax of the while test-commands; do consequent-commands; done Execute consequent-commands as long as the final command in test-commands has an exit status of zero. for The syntax of the for command is: for name [in words ...]; do commands; done Execute commands for each member in words, with name
bound to the current member. If `` Conditional Constructsif The syntax of the if test-commands; then consequent-commands; [elif more-test-commands; then more-consequents;] [else alternate-consequents;] fi Execute consequent-commands only if the final command in test-commands
has an exit status of zero. Otherwise, each case The syntax of the
Selectively execute commands based upon word matching pattern.
The ` Here is an example using echo -n "Enter the name of an animal: " read ANIMAL echo -n "The $ANIMAL has " case $ANIMAL in horse | dog | cat) echo -n "four";; man | kangaroo ) echo -n "two";; *) echo -n "an unknown number of";; esac echo "legs." Shell FunctionsShell functions are a way to group commands for later execution using a single name for the group. They are executed just like a "regular" command. Shell functions are executed in the current shell context; no new process is created to interpret them. Functions are declared using this syntax:
[
This defines a function named name. The body of the function is the command-list between { and }. This list is executed whenever name is specified as the name of a command. The exit status of a function is the exit status of the last command executed in the body. When a function is executed, the arguments to the function become the positional
parameters during its execution. The special parameter If the builtin command Bourne Shell BuiltinsThe following shell builtin commands are inherited from the Bourne shell. These commands are implemented as specified by the Posix 1003.2 standard.
Bourne Shell VariablesBash uses certain shell variables in the same way as the Bourne shell. In some cases, Bash assigns a default value to the variable.
Other Bourne Shell Features
Bash implements essentially the same grammar, parameter and variable expansion, redirection, and quoting as the Bourne Shell. Bash uses the Posix 1003.2 standard as the specification of how these features are to be implemented. There are some differences between the traditional Bourne shell and the Posix standard; this section quickly details the differences of significance. A number of these differences are explained in greater depth in subsequent sections. Major Differences from the Bourne ShellBash implements the Bash includes brace expansion (see section Brace Expansion). Bash includes the Posix and The Posix and Variables present in the shell's initial environment are automatically exported to
child processes. The Bourne shell does not normally do this unless the variables are
explicitly marked using the The expansion The It is possible to have a variable and a function with the same name; Bash functions are permitted to have local variables, and thus useful recursive functions may be written. The Bash allows you to write a function to override a builtin, and provides access to that
builtin's functionality within the function via the The Individual builtins may be enabled or disabled using the Functions may be exported to children via the environment. The Bash The The The
|
|
|
Email addresses listed on this site may NOT be used for unsolicited commercial email. Ready-to-Run Software, Inc Privacy Statement Portions (c)Copyright, 1996-2005 by
Ready-to-Run
Software, Inc |