Correct internal links across all .md files

This commit is contained in:
Rawiri Blundell 2023-04-24 23:31:29 +12:00
parent 39591d2ff9
commit cb82c31d36
63 changed files with 516 additions and 516 deletions

View File

@ -1,11 +1,11 @@
# Bash 4 - a rough overview # Bash 4 - a rough overview
| :shell: Attention: Since Bash 4 has been around for quite some time now (4.3 will come soon), I consider it to be "standard". This page is not maintained anymore and is left here to keep your links working. See the [bashchanges](/scripting/bashchanges) page for new stuff introduced. | | :shell: Attention: Since Bash 4 has been around for quite some time now (4.3 will come soon), I consider it to be "standard". This page is not maintained anymore and is left here to keep your links working. See the [bashchanges](/scripting/bashchanges.md) page for new stuff introduced. |
| --- | | --- |
Besides many bugfixes since Bash 3.2, Bash 4 will bring some interesting Besides many bugfixes since Bash 3.2, Bash 4 will bring some interesting
new features for shell users and scripters. See also new features for shell users and scripters. See also
[bashchanges](/scripting/bashchanges) for a small general overview with [bashchanges](/scripting/bashchanges.md) for a small general overview with
more details. more details.
Not all of the changes and news are included here, just the biggest or Not all of the changes and news are included here, just the biggest or
@ -33,7 +33,7 @@ files that represent the filedescriptors of the started process.
In other words: It lets you start a process in background and In other words: It lets you start a process in background and
communicate with its input and output data streams. communicate with its input and output data streams.
See [The coproc keyword](/syntax/keywords/coproc) See [The coproc keyword](/syntax/keywords/coproc.md)
### The new "mapfile" builtin ### The new "mapfile" builtin
@ -42,7 +42,7 @@ an array. This avoids having to fill an array yourself using a loop. It
enables you to define the range of lines to read, and optionally call a enables you to define the range of lines to read, and optionally call a
callback, for example to display a progress bar. callback, for example to display a progress bar.
See: [mapfile](/commands/builtin/mapfile) See: [mapfile](/commands/builtin/mapfile.md)
### Changes to the "case" keyword ### Changes to the "case" keyword
@ -54,7 +54,7 @@ list (rather than terminate the `case` construct).
The `;;&` terminator causes the `case` construct to test the next given The `;;&` terminator causes the `case` construct to test the next given
pattern instead of terminating the whole execution. pattern instead of terminating the whole execution.
See [case](/syntax/ccmd/case) See [case](/syntax/ccmd/case.md)
### Changes to the "declare" builtin ### Changes to the "declare" builtin
@ -85,7 +85,7 @@ A new option, `-i`, was introduced to be able to preload the input
buffer with some text (when Readline is used, with `-e`). The user is buffer with some text (when Readline is used, with `-e`). The user is
able to change the text, or press return to accept it. able to change the text, or press return to accept it.
See [read](/commands/builtin/read) See [read](/commands/builtin/read.md)
### Changes to the "help" builtin ### Changes to the "help" builtin
@ -109,7 +109,7 @@ Besides the use of the 512 bytes blocksize everywhere in POSIX mode,
The brace expansion was tuned to provide expansion results with leading The brace expansion was tuned to provide expansion results with leading
zeros when requesting a row of numbers. zeros when requesting a row of numbers.
See [brace](/syntax/expansion/brace) See [brace](/syntax/expansion/brace.md)
### Parameter Expansion ### Parameter Expansion
@ -119,7 +119,7 @@ On expansion time you can modify the syntax by adding operators to the
parameter name. parameter name.
See [Case modification on parameter See [Case modification on parameter
expansion](/syntax/pe#case_modification) expansion](/syntax/pe.md#case_modification)
### Substring expansion ### Substring expansion
@ -140,7 +140,7 @@ current level.
The new shell option `dirspell` enables spelling corrections on The new shell option `dirspell` enables spelling corrections on
directory names during globbing. directory names during globbing.
See [globs](/syntax/expansion/globs) See [globs](/syntax/expansion/globs.md)
## Associative Arrays ## Associative Arrays
@ -156,7 +156,7 @@ something like
ASSOC[Hello]="second element" ASSOC[Hello]="second element"
ASSOC[Peter Pan]="A weird guy" ASSOC[Peter Pan]="A weird guy"
See [arrays](/syntax/arrays) See [arrays](/syntax/arrays.md)
## Redirection ## Redirection
@ -167,17 +167,17 @@ good old `>>FILE 2>&1` notation.
The parser now understands `|&` as a synonym for `2>&1 |`, which The parser now understands `|&` as a synonym for `2>&1 |`, which
redirects the standard error for a command through a pipe. redirects the standard error for a command through a pipe.
See [redirection](/syntax/redirection) See [redirection](/syntax/redirection.md)
## Interesting new shell variables ## Interesting new shell variables
| Variable | Description | | Variable | Description |
|----------------------------------------------------|--------------------------------------------------------------------------------| |----------------------------------------------------|--------------------------------------------------------------------------------|
| [BASHPID](/syntax/shellvars#BASHPID) | contains the PID of the current shell (this is different than what `$$` does!) | | [BASHPID](/syntax/shellvars.md#BASHPID) | contains the PID of the current shell (this is different than what `$$` does!) |
| [PROMPT_DIRTRIM](/syntax/shellvars#PROMPT_DIRTRIM) | specifies the max. level of unshortened pathname elements in the prompt | | [PROMPT_DIRTRIM](/syntax/shellvars.md#PROMPT_DIRTRIM) | specifies the max. level of unshortened pathname elements in the prompt |
| [FUNCNEST](/syntax/shellvars#FUNCNEST) | control the maximum number of shell function recursions | | [FUNCNEST](/syntax/shellvars.md#FUNCNEST) | control the maximum number of shell function recursions |
See [shellvars](/syntax/shellvars) See [shellvars](/syntax/shellvars.md)
## Interesting new Shell Options ## Interesting new Shell Options
@ -192,7 +192,7 @@ mentioned.
| `globstar` | enables recursive globbing with `**` | | `globstar` | enables recursive globbing with `**` |
| `lastpipe` | (4.2) to execute the last command in a pipeline in the current environment | | `lastpipe` | (4.2) to execute the last command in a pipeline in the current environment |
See [shell_options](/internals/shell_options) See [shell_options](/internals/shell_options.md)
## Misc ## Misc
@ -205,7 +205,7 @@ See [shell_options](/internals/shell_options)
- The output target for the `xtrace` (`set -x`/`set +x`) feature is - The output target for the `xtrace` (`set -x`/`set +x`) feature is
configurable **since Bash 4.1** (previously, it was fixed to configurable **since Bash 4.1** (previously, it was fixed to
`stderr`): a variable named `stderr`): a variable named
[BASH_XTRACEFD](/syntax/shellvars#BASH_XTRACEFD) can be set to the [BASH_XTRACEFD](/syntax/shellvars.md#BASH_XTRACEFD) can be set to the
filedescriptor that should get the output filedescriptor that should get the output
- Bash 4.1 is able to log the history to syslog (only to be enabled at - Bash 4.1 is able to log the history to syslog (only to be enabled at
compile time in `config-top.h`) compile time in `config-top.h`)

View File

@ -155,6 +155,6 @@ for details. ksh93 namerefs are much more powerful than Bash's.
## See also ## See also
- [arrays](/syntax/arrays) - [arrays](/syntax/arrays.md)
- [readonly](/commands/builtin/readonly) - [readonly](/commands/builtin/read.mdonly)
- [unset](/commands/builtin/unset) - [unset](/commands/builtin/unset.md)

View File

@ -8,7 +8,7 @@
`echo` outputs it's args to stdout, separated by spaces, followed by a `echo` outputs it's args to stdout, separated by spaces, followed by a
newline. The return status is always `0`. If the newline. The return status is always `0`. If the
[shopt](/commands/builtin/shopt) option `xpg_echo` is set, Bash [shopt](/commands/builtin/shopt.md) option `xpg_echo` is set, Bash
dynamically determines whether echo should expand escape characters dynamically determines whether echo should expand escape characters
(listed below) by default based on the current platform. `echo` doesn't (listed below) by default based on the current platform. `echo` doesn't
interpret `--` as the end of options, and will simply print this string interpret `--` as the end of options, and will simply print this string
@ -68,7 +68,7 @@ if given.
- **Never use options to `echo`! *Ever*!** Any time you feel tempted to - **Never use options to `echo`! *Ever*!** Any time you feel tempted to
use `echo -e`, `-n`, or any other special feature of echo, **use use `echo -e`, `-n`, or any other special feature of echo, **use
[printf](/commands/builtin/printf) instead!** If portability is a [printf](/commands/builtin/printf.md) instead!** If portability is a
requirement, you should consider using `printf` *exclusively* and just requirement, you should consider using `printf` *exclusively* and just
ignore that `echo` even exists. If you must use `echo -e` and refuse ignore that `echo` even exists. If you must use `echo -e` and refuse
to use `printf`, it is usually acceptable to use ''echo \$'...' ''if to use `printf`, it is usually acceptable to use ''echo \$'...' ''if
@ -78,11 +78,11 @@ if given.
- `ksh93` has a `print` command, which if coding specifically for - `ksh93` has a `print` command, which if coding specifically for
`ksh93` should be preferred over `echo`. `ksh93` should be preferred over `echo`.
[printf](/commands/builtin/printf) still includes most of the [printf](/commands/builtin/printf.md) still includes most of the
functionality of both, and should usually be the most preferred functionality of both, and should usually be the most preferred
option. option.
## See also ## See also
- [printf](/commands/builtin/printf) - [printf](/commands/builtin/printf.md)
- <http://cfajohnson.com/shell/cus-faq.html#Q0b> - <http://cfajohnson.com/shell/cus-faq.html#Q0b>

View File

@ -18,7 +18,7 @@ process.
## Examples ## Examples
In this example, the literal text within the In this example, the literal text within the
[here-document](/syntax/redirection#here_documents) is executed as Bash [here-document](/syntax/redirection.md#here_documents) is executed as Bash
code exactly as though it were to appear within the script in place of code exactly as though it were to appear within the script in place of
the `eval` command below it. the `eval` command below it.

View File

@ -28,7 +28,7 @@ shell without executing any program.
- on redirection errors it returns 1, otherwise 0 - on redirection errors it returns 1, otherwise 0
- on exec failures: - on exec failures:
- a non-interactive shell terminates; if the [shell option - a non-interactive shell terminates; if the [shell option
execfail](/internals/shell_options#execfail) is set `exec` returns execfail](/internals/shell_options.md#execfail) is set `exec` returns
failure failure
- in an interactive shell, `exec` returns failure - in an interactive shell, `exec` returns failure
@ -82,4 +82,4 @@ exec >/var/adm/my.log 2>&1
## See also ## See also
- [redirection](/syntax/redirection) - [redirection](/syntax/redirection.md)

View File

@ -49,4 +49,4 @@ Set your default text editor (e.g. SublimeText):
## See also ## See also
- [declare](/commands/builtin/declare) - [declare](/commands/builtin/declare.md)

View File

@ -7,27 +7,27 @@
## Description ## Description
The `let` builtin command evaluates each supplied word from left to The `let` builtin command evaluates each supplied word from left to
right as an [arithmetic expression](/syntax/arith_expr) and returns an right as an [arithmetic expression](/syntax/arith_expr.md) and returns an
exit code according to the truth value of the rightmost expression. exit code according to the truth value of the rightmost expression.
- 0 (TRUE) when `arg` evaluated to not 0 (arithmetic "true") - 0 (TRUE) when `arg` evaluated to not 0 (arithmetic "true")
- 1 (FALSE) when `arg` evaluated to 0 (arithmetic "false") - 1 (FALSE) when `arg` evaluated to 0 (arithmetic "false")
For this return code mapping, please see [this For this return code mapping, please see [this
section](/syntax/arith_expr#arithmetic_expressions_and_return_codes). section](/syntax/arith_expr.md#arithmetic_expressions_and_return_codes).
They work in the same way as `((`. They work in the same way as `((`.
## Examples ## Examples
`let` is very similar to [((](/syntax/ccmd/arithmetic_eval) - the only `let` is very similar to [((](/syntax/ccmd/arithmetic_eval.md) - the only
difference being `let` is a builtin (simple command), and `((` is a difference being `let` is a builtin (simple command), and `((` is a
compound command. The arguments to `let` are therefore subject to all compound command. The arguments to `let` are therefore subject to all
the same expansions and substitutions as any other simple command - the same expansions and substitutions as any other simple command -
requiring proper quoting and escaping - whereas the contents of `((` requiring proper quoting and escaping - whereas the contents of `((`
aren't subject to [word-splitting](/syntax/expansion/wordsplit) or aren't subject to [word-splitting](/syntax/expansion/wordsplit.md) or
[pathname expansion](/syntax/expansion/globs) (almost never desirable [pathname expansion](/syntax/expansion/globs.md) (almost never desirable
for arithmetic). For this reason, **the [arithmetic compound for arithmetic). For this reason, **the [arithmetic compound
command](/syntax/ccmd/arithmetic_eval) should generally be preferred command](/syntax/ccmd/arithmetic_eval.md) should generally be preferred
over `let`**. over `let`**.
$ let 'b = a' "(a += 3) + $((a = 1)), b++" $ let 'b = a' "(a += 3) + $((a = 1)), b++"
@ -35,7 +35,7 @@ over `let`**.
4 - 2 - 0 4 - 2 - 0
Is equivalent to the [arithmetic evaluation compound Is equivalent to the [arithmetic evaluation compound
command](/syntax/ccmd/arithmetic_eval): command](/syntax/ccmd/arithmetic_eval.md):
$ (( b = a, (a += 3) + $((a = 1)), b++ )) $ (( b = a, (a += 3) + $((a = 1)), b++ ))
$ echo "$a - $b - $?" $ echo "$a - $b - $?"
@ -86,7 +86,7 @@ needed.
- [expr(1)](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html#tag_20_42) - [expr(1)](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html#tag_20_42)
is a command one is likely to come across sooner or later. While it is is a command one is likely to come across sooner or later. While it is
more "standard" than `let`, the above should always be preferred. Both more "standard" than `let`, the above should always be preferred. Both
[arithmetic expansion](/syntax/arith_expr)s and the `[` test operator [arithmetic expansion](/syntax/arith_expr.md)s and the `[` test operator
are specified by POSIX(r) and satisfy almost all of expr's use-cases. are specified by POSIX(r) and satisfy almost all of expr's use-cases.
Unlike `let`, `expr` cannot assign directly to bash variables but Unlike `let`, `expr` cannot assign directly to bash variables but
instead returns a result on stdout. `expr` takes each operator it instead returns a result on stdout. `expr` takes each operator it
@ -104,7 +104,7 @@ needed.
## See also ## See also
- Internal: [arithmetic expansion](/syntax/expansion/arith) - Internal: [arithmetic expansion](/syntax/expansion/arith.md)
- Internal: [arithmetic expressions](/syntax/arith_expr) - Internal: [arithmetic expressions](/syntax/arith_expr.md)
[^1]: ... [^1]: ...

View File

@ -6,7 +6,7 @@
## Description ## Description
`local` is identical to [declare](/commands/builtin/declare) in every `local` is identical to [declare](/commands/builtin/declare.md) in every
way, and takes all the same options, with two exceptions: way, and takes all the same options, with two exceptions:
- Usage outside of a function is an error. Both `declare` and `local` - Usage outside of a function is an error. Both `declare` and `local`

View File

@ -214,7 +214,7 @@ each subsequent 2 iterations. The RETURN trap is unimportant.
## See also ## See also
- [arrays](/syntax/arrays) - [arrays](/syntax/arrays.md)
- [read](/commands/builtin/read) - If you don't know about this yet, why - [read](/commands/builtin/read.md) - If you don't know about this yet, why
are you reading this page? are you reading this page?
- <http://mywiki.wooledge.org/BashFAQ/001> - It's FAQ 1 for a reason. - <http://mywiki.wooledge.org/BashFAQ/001> - It's FAQ 1 for a reason.

View File

@ -93,9 +93,9 @@ the format string is re-used until the last argument is interpreted. If
fewer format specifiers than arguments are present, then number-formats fewer format specifiers than arguments are present, then number-formats
are set to zero, while string-formats are set to null (empty). are set to zero, while string-formats are set to null (empty).
Take care to avoid [word splitting](/syntax/expansion/wordsplit), as Take care to avoid [word splitting](/syntax/expansion/wordsplit.md), as
accidentally passing the wrong number of arguments can produce wildly accidentally passing the wrong number of arguments can produce wildly
different and unexpected results. See [this article](/syntax/words). different and unexpected results. See [this article](/syntax/words.md).
| :warning: <u>**Again, attention:**</u> When a numerical format | :warning: <u>**Again, attention:**</u> When a numerical format
expects a number, the internal `printf`-command will use the common Bash expects a number, the internal `printf`-command will use the common Bash
@ -454,7 +454,7 @@ fmt++;
- Assigning to variables: The `printf -v` way is slightly different to - Assigning to variables: The `printf -v` way is slightly different to
the way using command-substitution. [Command the way using command-substitution. [Command
substitution](/syntax/expansion/cmdsubst) removes trailing newlines substitution](/syntax/expansion/cmdsubst.md) removes trailing newlines
before substituting the text, `printf -v` preserves all output. before substituting the text, `printf -v` preserves all output.
## See also ## See also

View File

@ -16,13 +16,13 @@ Since Bash 4.3-alpha, `read` skips any `NUL` (ASCII code 0) characters
in input. in input.
If `<NAME...>` is given, the line is word-split using If `<NAME...>` is given, the line is word-split using
[IFS](/syntax/shellvars#IFS) variable, and every word is assigned to one [IFS](/syntax/shellvars.md#IFS) variable, and every word is assigned to one
`<NAME>`. The remaining words are all assigned to the last `<NAME>` if `<NAME>`. The remaining words are all assigned to the last `<NAME>` if
more words than variable names are present. more words than variable names are present.
\<WRAP center round info 90%\> If no `<NAME>` is given, the whole line \<WRAP center round info 90%\> If no `<NAME>` is given, the whole line
read (without performing word-splitting!) is assigned to the shell read (without performing word-splitting!) is assigned to the shell
variable [REPLY](/syntax/shellvars#REPLY). Then, `REPLY` really contains variable [REPLY](/syntax/shellvars.md#REPLY). Then, `REPLY` really contains
the line as it was read, without stripping pre- and postfix spaces and the line as it was read, without stripping pre- and postfix spaces and
other things! other things!
@ -33,7 +33,7 @@ other things!
\</WRAP\> \</WRAP\>
If a timeout is given, or if the shell variable If a timeout is given, or if the shell variable
[TMOUT](/syntax/shellvars#TMOUT) is set, it is counted from initially [TMOUT](/syntax/shellvars.md#TMOUT) is set, it is counted from initially
waiting for input until the completion of input (i.e. until the complete waiting for input until the completion of input (i.e. until the complete
line is read). That means the timeout can occur during input, too. line is read). That means the timeout can occur during input, too.
@ -64,7 +64,7 @@ Of course it's valid to set individual array elements without using
\<WRAP center round important 90%\> \<WRAP center round important 90%\>
Reading into array elements using the syntax above **may cause [pathname Reading into array elements using the syntax above **may cause [pathname
expansion](/syntax/expansion/globs) to occur**. expansion](/syntax/expansion/globs.md) to occur**.
Example: You are in a directory with a file named `x1`, and you want to Example: You are in a directory with a file named `x1`, and you want to
read into an array `x`, index `1` with read into an array `x`, index `1` with
@ -172,7 +172,7 @@ Take care that you cannot use a pipe:
Why? because the commands of the pipe run in subshells that cannot Why? because the commands of the pipe run in subshells that cannot
modify the parent shell. As a result, the variables `col1`, `col2` and modify the parent shell. As a result, the variables `col1`, `col2` and
`col3` of the parent shell are not modified (see article: `col3` of the parent shell are not modified (see article:
[processtree](/scripting/processtree)). [processtree](/scripting/processtree.md)).
If the variable has more fields than there are variables, the last If the variable has more fields than there are variables, the last
variable get the remaining of the line: variable get the remaining of the line:
@ -184,7 +184,7 @@ variable get the remaining of the line:
By default reads separates the line in fields using spaces or tabs. You By default reads separates the line in fields using spaces or tabs. You
can modify this using the *special variable* can modify this using the *special variable*
[IFS](/syntax/shellvars#IFS), the Internal Field Separator. [IFS](/syntax/shellvars.md#IFS), the Internal Field Separator.
IFS=":" read -r col1 col2 <<< "hello:world" IFS=":" read -r col1 col2 <<< "hello:world"
printf "col1: %s col2: %s\n" "$col1" "$col2" printf "col1: %s col2: %s\n" "$col1" "$col2"
@ -264,6 +264,6 @@ date/time string are recognized correctly.
## See also ## See also
- Internal: [The printf builtin command](/commands/builtin/printf) - Internal: [The printf builtin command](/commands/builtin/printf.md)
[^1]: fixed in 4.2-rc1 [^1]: fixed in 4.2-rc1

View File

@ -41,4 +41,4 @@ An argument of `--` disables further option processing.
## See also ## See also
- [declare](/commands/builtin/declare) - [declare](/commands/builtin/declare.md)

View File

@ -11,7 +11,7 @@ FIXME incomplete - text, examples, maybe extended description
`set` is primarily made to `set` is primarily made to
- set the positional parameters (see [handling positional - set the positional parameters (see [handling positional
parameters](/scripting/posparams)) to `<POSPARAMS>` parameters](/scripting/posparams.md)) to `<POSPARAMS>`
- set shell attributes with short options (see below) - set shell attributes with short options (see below)
- set shell attributes with long option names (see below) - set shell attributes with long option names (see below)
@ -29,7 +29,7 @@ set flags (true for most commands on UNIX(r)).
| `-a` | `allexport` | Automatically mark new and altered variables to be exported to subsequent environments. | | `-a` | `allexport` | Automatically mark new and altered variables to be exported to subsequent environments. |
| `-b` | `notify` | Don't wait for the next prompt to print when showing the reports for a terminated background job (only with job control) | | `-b` | `notify` | Don't wait for the next prompt to print when showing the reports for a terminated background job (only with job control) |
| `-e` | `errexit` | When set, the shell exits when a simple command in a command list exits non-zero (`FALSE`). This is not done in situations, where the exit code is already checked (`if`, `while`, `until`, `||`, `&&`) | | `-e` | `errexit` | When set, the shell exits when a simple command in a command list exits non-zero (`FALSE`). This is not done in situations, where the exit code is already checked (`if`, `while`, `until`, `||`, `&&`) |
| `-f` | `noglob` | Disable [pathname expansion](/syntax/expansion/globs) (globbing) | | `-f` | `noglob` | Disable [pathname expansion](/syntax/expansion/globs.md) (globbing) |
| `-h` | `hashall` | Remembers the location of commands when they're called (hashing). Enabled by default. | | `-h` | `hashall` | Remembers the location of commands when they're called (hashing). Enabled by default. |
| `-k` | `keyword` | Allows to place environment-assignments everywhere in the commandline, not only infront of the called command. | | `-k` | `keyword` | Allows to place environment-assignments everywhere in the commandline, not only infront of the called command. |
| `-m` | `monitor` | **Monitor mode**. With job control, a short descriptive line is printed when a backgroud job ends. Default is "on" for interactive shells (with job control). | | `-m` | `monitor` | **Monitor mode**. With job control, a short descriptive line is printed when a backgroud job ends. Default is "on" for interactive shells (with job control). |
@ -40,8 +40,8 @@ set flags (true for most commands on UNIX(r)).
| `-u` | `nounset` | Treat unset variables as an error when performing parameter expansion. Non-interactive shells exit on this error. | | `-u` | `nounset` | Treat unset variables as an error when performing parameter expansion. Non-interactive shells exit on this error. |
| `-v` | `verbose` | Print shell input lines as they are read - useful for debugging. | | `-v` | `verbose` | Print shell input lines as they are read - useful for debugging. |
| `-x` | `xtrace` | Print commands just before execution - with all expansions and substitutions done, and words marked - useful for debugging. | | `-x` | `xtrace` | Print commands just before execution - with all expansions and substitutions done, and words marked - useful for debugging. |
| `-B` | `braceexpand` | The shell performs [brace expansion](/syntax/expansion/brace) This is on by default. | | `-B` | `braceexpand` | The shell performs [brace expansion](/syntax/expansion/brace.md) This is on by default. |
| `-C` | \<BOOKMARK:tag_noclobber\>`noclobber` | Don't overwrite files on redirection operations. You can override that by specifying the `>|` redirection operator when needed. See [redirection](/syntax/redirection) | | `-C` | \<BOOKMARK:tag_noclobber\>`noclobber` | Don't overwrite files on redirection operations. You can override that by specifying the `>|` redirection operator when needed. See [redirection](/syntax/redirection.md) |
| `-E` | `errtrace` | `ERR`-traps are inherited by by shell functions, command substitutions, and commands executed in a subshell environment. | | `-E` | `errtrace` | `ERR`-traps are inherited by by shell functions, command substitutions, and commands executed in a subshell environment. |
| `-H` | `histexpand` | Enable `!`-style history expansion. Defaults to `on` for interactive shells. | | `-H` | `histexpand` | Enable `!`-style history expansion. Defaults to `on` for interactive shells. |
| `-P` | `physical` | Don't follow symlinks when changing directories - use the physical filesystem structure. | | `-P` | `physical` | Don't follow symlinks when changing directories - use the physical filesystem structure. |
@ -51,7 +51,7 @@ set flags (true for most commands on UNIX(r)).
| | Long options usable with `-o` without a short equivalent | | | | Long options usable with `-o` without a short equivalent | |
| | `emacs` | Use an emacs-style command line editing interface. This is enabled by default when the shell is interactive, unless the shell is started with `--noediting` option. | | | `emacs` | Use an emacs-style command line editing interface. This is enabled by default when the shell is interactive, unless the shell is started with `--noediting` option. |
| | `history` | If set, command historization is done (enabled by default on interactive shells) | | | `history` | If set, command historization is done (enabled by default on interactive shells) |
| | `ignoreeof` | The effect is as if the shell command `IGNOREEOF=10` had been executed. See [shell variables](/syntax/shellvars). | | | `ignoreeof` | The effect is as if the shell command `IGNOREEOF=10` had been executed. See [shell variables](/syntax/shellvars.md). |
| | `nolog` | **(currently ignored)** | | | `nolog` | **(currently ignored)** |
| | `pipefail` | If set, the exit code from a pipeline is different from the normal ("last command in pipeline") behaviour: `TRUE` when no command failed, `FALSE` when something failed (code of the rightmost command that failed) | | | `pipefail` | If set, the exit code from a pipeline is different from the normal ("last command in pipeline") behaviour: `TRUE` when no command failed, `FALSE` when something failed (code of the rightmost command that failed) |
| | `posix` | When set, Bash runs in POSIX mode. | | | `posix` | When set, Bash runs in POSIX mode. |
@ -78,4 +78,4 @@ naturally.
## See also ## See also
- Internal: [The shopt builtin command](/commands/builtin/shopt) - Internal: [The shopt builtin command](/commands/builtin/shopt.md)

View File

@ -28,7 +28,7 @@ When you use `shift 1`, they will be changed to:
| 2 | a | | 2 | a |
| 3 | test | | 3 | test |
The [special parameter](/syntax/shellvars#special_parameters) `$#` will The [special parameter](/syntax/shellvars.md#special_parameters) `$#` will
reflect the final number of positional parameters. reflect the final number of positional parameters.
If the number given is 0, no changes are made to the positional If the number given is 0, no changes are made to the positional

View File

@ -1,6 +1,6 @@
# The shopt builtin command # The shopt builtin command
The `shopt` builtin manages [shell options](/internals/shell_options), a The `shopt` builtin manages [shell options](/internals/shell_options.md), a
set of boolean (`on`/`off`) configuration variables that control the set of boolean (`on`/`off`) configuration variables that control the
behaviour of the shell. behaviour of the shell.
@ -11,13 +11,13 @@ behaviour of the shell.
## Description ## Description
Note: Some of these options and other shell options can also be set with Note: Some of these options and other shell options can also be set with
[the set builtin](/commands/builtin/set). [the set builtin](/commands/builtin/set.md).
### Options ### Options
| Option | Description | | Option | Description |
|--------|--------------------------------------------------------------------------------------------------------------------------| |--------|--------------------------------------------------------------------------------------------------------------------------|
| `-o` | Restrict the values of `<OPTNAME...>` to only those also known by [the set builtin](/commands/builtin/set) | | `-o` | Restrict the values of `<OPTNAME...>` to only those also known by [the set builtin](/commands/builtin/set.md) |
| `-p` | Print all shell options and their current value. **Default**. | | `-p` | Print all shell options and their current value. **Default**. |
| `-q` | Quiet mode. Set exit code if named option is set. For multiple options: `TRUE` if all options are set, `FALSE` otherwise | | `-q` | Quiet mode. Set exit code if named option is set. For multiple options: `TRUE` if all options are set, `FALSE` otherwise |
| `-s` | Enable (<u>s</u>et) the shell options named by `<OPTNAME...>` or list all *enabled* options if no names are given | | `-s` | Enable (<u>s</u>et) the shell options named by `<OPTNAME...>` or list all *enabled* options if no names are given |
@ -47,5 +47,5 @@ The `shopt` command is not portable accross different shells.
## See also ## See also
- Internal: [The set builtin command](/commands/builtin/set) - Internal: [The set builtin command](/commands/builtin/set.md)
- Internal: [List of shell options](/internals/shell_options) - Internal: [List of shell options](/internals/shell_options.md)

View File

@ -34,7 +34,7 @@ Special events
| `EXIT` | 0 | executed on shell exit | | `EXIT` | 0 | executed on shell exit |
| `DEBUG` | | executed before every simple command | | `DEBUG` | | executed before every simple command |
| `RETURN` | | executed when a shell function or a sourced code finishes executing | | `RETURN` | | executed when a shell function or a sourced code finishes executing |
| `ERR` | | executed each time a command's failure would cause the shell to exit when the [`-e` option (`errexit`)](/commands/builtin/set) is enabled | | `ERR` | | executed each time a command's failure would cause the shell to exit when the [`-e` option (`errexit`)](/commands/builtin/set.md) is enabled |
### Options ### Options
@ -68,5 +68,5 @@ Special events
## See also ## See also
- [the set command](/commands/builtin/set) for the `-e` (`errexit`) - [the set command](/commands/builtin/set.md) for the `-e` (`errexit`)
option option

View File

@ -175,5 +175,5 @@ using `unset`. Also, I prefer it as a matter of style.
## See also ## See also
- [declare](/commands/builtin/declare) - [declare](/commands/builtin/declare.md)
- [unset](/commands/builtin/unset) - [unset](/commands/builtin/unset.md)

View File

@ -67,7 +67,7 @@ normal ordinary command ("test" or "\[") the shell will word-split the
expansion of the variable `mymusic`: You need to quote it when you don't expansion of the variable `mymusic`: You need to quote it when you don't
want the `test`-command to complain about too many arguments for this want the `test`-command to complain about too many arguments for this
test-type! If you didn't understand it, please read the [article about test-type! If you didn't understand it, please read the [article about
words...](/syntax/words) words...](/syntax/words.md)
Please also note that the file-tests want **one filename** to test. Please also note that the file-tests want **one filename** to test.
Don't give a glob (filename-wildcards) as it can expand to many Don't give a glob (filename-wildcards) as it can expand to many
@ -147,7 +147,7 @@ ACLs, if the underlying filesystem/OS supports them.
| \<TEST1\> **-o** \<TEST2\> | True, if either \<TEST1\> **or** \<TEST2\> is true (OR). | | \<TEST1\> **-o** \<TEST2\> | True, if either \<TEST1\> **or** \<TEST2\> is true (OR). |
| **!** \<TEST\> | True, if \<TEST\> is **false** (NOT). | | **!** \<TEST\> | True, if \<TEST\> is **false** (NOT). |
| **(** \<TEST\> **)** | Group a test (for precedence). **Attention:** In normal shell-usage, the "(" and ")" must be escaped; use "\\" and "\\"! | | **(** \<TEST\> **)** | Group a test (for precedence). **Attention:** In normal shell-usage, the "(" and ")" must be escaped; use "\\" and "\\"! |
| **-o** \<OPTION_NAME\> | True, if the [shell option](/internals/shell_options) \<OPTION_NAME\> is set. | | **-o** \<OPTION_NAME\> | True, if the [shell option](/internals/shell_options.md) \<OPTION_NAME\> is set. |
| **-v** \<VARIABLENAME\> | True if the variable \<VARIABLENAME\> has been set. Use `var[n]` for array elements. | | **-v** \<VARIABLENAME\> | True if the variable \<VARIABLENAME\> has been set. Use `var[n]` for array elements. |
| **-R** \<VARIABLENAME\> | True if the variable \<VARIABLENAME\> has been set and is a nameref variable (since 4.3-alpha) | | **-R** \<VARIABLENAME\> | True if the variable \<VARIABLENAME\> has been set and is a nameref variable (since 4.3-alpha) |
@ -539,7 +539,7 @@ Some code snipplets follow, different ways of shell reaction is used.
- `[ "$MYVAR" ]` - `[ "$MYVAR" ]`
- **Note:** There are possibilities to make a difference if a variable - **Note:** There are possibilities to make a difference if a variable
is *undefined* or *NULL* - see [Parameter Expansion - Using an is *undefined* or *NULL* - see [Parameter Expansion - Using an
alternate value](/syntax/pe#use_an_alternate_value) alternate value](/syntax/pe.md#use_an_alternate_value)
- **check if a directory exists, if not, create it** - **check if a directory exists, if not, create it**
- `test ! -d /home/user/foo && mkdir /home/user/foo` - `test ! -d /home/user/foo && mkdir /home/user/foo`
- `[ ! -d /home/user/foo ] && mkdir /home/user/foo` - `[ ! -d /home/user/foo ] && mkdir /home/user/foo`
@ -547,11 +547,11 @@ Some code snipplets follow, different ways of shell reaction is used.
- **check if minimum one parameter was given, and that one is "Hello"** - **check if minimum one parameter was given, and that one is "Hello"**
- `test $# -ge 1 -a "$1" = "Hello" || exit 1` - `test $# -ge 1 -a "$1" = "Hello" || exit 1`
- `[ $# -ge 1 ] && [ "$1" = "Hello" ] || exit 1` (see [lists - `[ $# -ge 1 ] && [ "$1" = "Hello" ] || exit 1` (see [lists
description](/syntax/basicgrammar#lists)) description](/syntax/basicgrammar.md#lists))
### Listing directories ### Listing directories
Using a [for-loop](/syntax/ccmd/classic_for) to iterate through all Using a [for-loop](/syntax/ccmd/classic_for.md) to iterate through all
entries of a directory, if an entry is a directory (`[ -d "$fn" ]`), entries of a directory, if an entry is a directory (`[ -d "$fn" ]`),
print its name: print its name:
@ -562,7 +562,7 @@ print its name:
## See also ## See also
- Internal: [conditional - Internal: [conditional
expression](/syntax/ccmd/conditional_expression) (aka "the new test expression](/syntax/ccmd/conditional_expression.md) (aka "the new test
command") command")
[^1]: \<rant\>Of course, one can wonder what is the use of including the [^1]: \<rant\>Of course, one can wonder what is the use of including the

View File

@ -31,13 +31,13 @@ The goal here seems to be get the filename without its `.zip` extension.
In fact, there is a POSIX(r)-compliant command to do this: `basename` In fact, there is a POSIX(r)-compliant command to do this: `basename`
The implementation here is suboptimal in several ways, but the only The implementation here is suboptimal in several ways, but the only
thing that's genuinely error-prone with this is "`echo $i`". Echoing an thing that's genuinely error-prone with this is "`echo $i`". Echoing an
*unquoted* variable means [wordsplitting](/syntax/expansion/wordsplit) *unquoted* variable means [wordsplitting](/syntax/expansion/wordsplit.md)
will take place, so any whitespace in `$i` will essentially be will take place, so any whitespace in `$i` will essentially be
normalized. In `sh` it is necessary to use an external command and a normalized. In `sh` it is necessary to use an external command and a
subshell to achieve the goal, but we can eliminate the pipe (subshells, subshell to achieve the goal, but we can eliminate the pipe (subshells,
external commands, and pipes carry extra overhead when they launch, so external commands, and pipes carry extra overhead when they launch, so
they can really hurt performance in a loop). Just for good measure, they can really hurt performance in a loop). Just for good measure,
let's use the more readable, [modern](/syntax/expansion/cmdsubst) `$()` let's use the more readable, [modern](/syntax/expansion/cmdsubst.md) `$()`
construct instead of the old style backticks: construct instead of the old style backticks:
``` bash ``` bash
@ -46,7 +46,7 @@ sh $ for i in *.zip; do j=$(basename "$i" ".zip"); mkdir $j; cd $j; unzip ../$i;
In Bash we don't need the subshell or the external basename command. See In Bash we don't need the subshell or the external basename command. See
[Substring removal with parameter [Substring removal with parameter
expansion](/syntax/pe#substring_removal): expansion](/syntax/pe.md#substring_removal):
``` bash ``` bash
bash $ for i in *.zip; do j="${i%.zip}"; mkdir $j; cd $j; unzip ../$i; cd ..; done bash $ for i in *.zip; do j="${i%.zip}"; mkdir $j; cd $j; unzip ../$i; cd ..; done
@ -64,7 +64,7 @@ hurt: When a following command depends on the success of a previous
command(s), check for success! You can do this with the "`&&`" command(s), check for success! You can do this with the "`&&`"
conjunction, that way, if the previous command fails, bash will not try conjunction, that way, if the previous command fails, bash will not try
to execute the following command(s). It's fully POSIX(r). Oh, and to execute the following command(s). It's fully POSIX(r). Oh, and
remember what I said about [wordsplitting](/syntax/expansion/wordsplit) remember what I said about [wordsplitting](/syntax/expansion/wordsplit.md)
in the previous step? Well, if you don't quote `$j`, wordsplitting can in the previous step? Well, if you don't quote `$j`, wordsplitting can
happen again. happen again.

View File

@ -23,7 +23,7 @@ are:
Some other methods to parse positional parameters - using neither Some other methods to parse positional parameters - using neither
**getopt** nor **getopts** - are described in: [How to handle positional **getopt** nor **getopts** - are described in: [How to handle positional
parameters](/scripting/posparams). parameters](/scripting/posparams.md).
### Terminology ### Terminology
@ -88,9 +88,9 @@ which means [end of options](/dict/terms/end_of_options).
| variable | description | | variable | description |
|------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [OPTIND](/syntax/shellvars#OPTIND) | Holds the index to the next argument to be processed. This is how `getopts` "remembers" its own status between invocations. Also useful to shift the positional parameters after processing with `getopts`. `OPTIND` is initially set to 1, and **needs to be re-set to 1 if you want to parse anything again with getopts** | | [OPTIND](/syntax/shellvars.md#OPTIND) | Holds the index to the next argument to be processed. This is how `getopts` "remembers" its own status between invocations. Also useful to shift the positional parameters after processing with `getopts`. `OPTIND` is initially set to 1, and **needs to be re-set to 1 if you want to parse anything again with getopts** |
| [OPTARG](/syntax/shellvars#OPTARG) | This variable is set to any argument for an option found by `getopts`. It also contains the option flag of an unknown option. | | [OPTARG](/syntax/shellvars.md#OPTARG) | This variable is set to any argument for an option found by `getopts`. It also contains the option flag of an unknown option. |
| [OPTERR](/syntax/shellvars#OPTERR) | (Values 0 or 1) Indicates if Bash should display error messages generated by the `getopts` builtin. The value is initialized to **1** on every shell startup - so be sure to always set it to **0** if you don't want to see annoying messages! **`OPTERR` is not specified by POSIX for the `getopts` builtin utility --- only for the C `getopt()` function in `unistd.h` (`opterr`).** `OPTERR` is bash-specific and not supported by shells such as ksh93, mksh, zsh, or dash. | | [OPTERR](/syntax/shellvars.md#OPTERR) | (Values 0 or 1) Indicates if Bash should display error messages generated by the `getopts` builtin. The value is initialized to **1** on every shell startup - so be sure to always set it to **0** if you don't want to see annoying messages! **`OPTERR` is not specified by POSIX for the `getopts` builtin utility --- only for the C `getopt()` function in `unistd.h` (`opterr`).** `OPTERR` is bash-specific and not supported by shells such as ksh93, mksh, zsh, or dash. |
`getopts` also uses these variables for error reporting (they're set to `getopts` also uses these variables for error reporting (they're set to
value-combinations which arent possible in normal operation). value-combinations which arent possible in normal operation).
@ -133,7 +133,7 @@ messages.
#### Custom arguments to parse #### Custom arguments to parse
The `getopts` utility parses the [positional The `getopts` utility parses the [positional
parameters](/scripting/posparams) of the current shell or function by parameters](/scripting/posparams.md) of the current shell or function by
default (which means it parses `"$@"`). default (which means it parses `"$@"`).
You can give your own set of arguments to the utility to parse. Whenever You can give your own set of arguments to the utility to parse. Whenever
@ -345,9 +345,9 @@ Let's provide **the argument**:
## See also ## See also
- Internal: [posparams](/scripting/posparams) - Internal: [posparams](/scripting/posparams.md)
- Internal: [case](/syntax/ccmd/case) - Internal: [case](/syntax/ccmd/case.md)
- Internal: [while_loop](/syntax/ccmd/while_loop) - Internal: [while_loop](/syntax/ccmd/while_loop.md)
- POSIX - POSIX
[getopts(1)](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html#tag_20_54) [getopts(1)](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html#tag_20_54)
and and

View File

@ -6,7 +6,7 @@ This information was taken from a Bash version "`4.1`", every now and
then new options are added, so likely, this list isn't complete. then new options are added, so likely, this list isn't complete.
The shell-options can be set with the [shopt builtin The shell-options can be set with the [shopt builtin
command](/commands/builtin/shopt). command](/commands/builtin/shopt.md).
## Shell options ## Shell options
@ -78,8 +78,8 @@ stopped.
If set, Bash checks the window size after each command and, if If set, Bash checks the window size after each command and, if
necessary, updates the values of the variables necessary, updates the values of the variables
[LINES](/syntax/shellvars#LINES) and [LINES](/syntax/shellvars.md#LINES) and
[COLUMNS](/syntax/shellvars#COLUMNS). [COLUMNS](/syntax/shellvars.md#COLUMNS).
### cmdhist ### cmdhist
@ -174,7 +174,7 @@ match a glob.
| Shell mode: | all | Default: | off | | Shell mode: | all | Default: | off |
If set, Bash includes filenames beginning with a `.` (dot) in the If set, Bash includes filenames beginning with a `.` (dot) in the
results of [pathname expansion](/syntax/expansion/globs). results of [pathname expansion](/syntax/expansion/globs.md).
### execfail ### execfail
@ -209,7 +209,7 @@ If set, behavior intended for use by debuggers is enabled.
|:------------|:----------|:---------|:------------| |:------------|:----------|:---------|:------------|
| Shell mode: | all | Default: | off | | Shell mode: | all | Default: | off |
If set, the extended [pattern matching](/syntax/pattern) features are If set, the extended [pattern matching](/syntax/pattern.md) features are
enabled. See the important note below under [Parser enabled. See the important note below under [Parser
configurations](#parser_configurations). configurations](#parser_configurations).
@ -220,7 +220,7 @@ configurations](#parser_configurations).
| Shell mode: | all | Default: | on | | Shell mode: | all | Default: | on |
If set, `$'string'` and `$"string"` quoting is performed within If set, `$'string'` and `$"string"` quoting is performed within
[parameter expansions](/syntax/pe) enclosed in double quotes. See the [parameter expansions](/syntax/pe.md) enclosed in double quotes. See the
important note below under [Parser important note below under [Parser
configurations](#parser_configurations). configurations](#parser_configurations).
@ -240,7 +240,7 @@ result in an error message.
| Shell mode: | interactive | Default: | on | | Shell mode: | interactive | Default: | on |
If set, the suffixes specified by the If set, the suffixes specified by the
[FIGNORE](/syntax/shellvars#FIGNORE) shell variable cause words to be [FIGNORE](/syntax/shellvars.md#FIGNORE) shell variable cause words to be
ignored when performing word completion even if the ignored words are ignored when performing word completion even if the ignored words are
the only possible completions. This option is enabled by default. the only possible completions. This option is enabled by default.
@ -280,7 +280,7 @@ message format".
| Shell mode: | interactive (?) | Default: | off | | Shell mode: | interactive (?) | Default: | off |
If set, the history list is appended to the file named by the value of If set, the history list is appended to the file named by the value of
the [HISTFILE](/syntax/shellvars#HISTFILE) variable when the shell the [HISTFILE](/syntax/shellvars.md#HISTFILE) variable when the shell
exits, rather than overwriting the file. exits, rather than overwriting the file.
### histreedit ### histreedit
@ -324,7 +324,7 @@ interactive login shell exits.
|:------------|:-----------------------|:---------|:--------| |:------------|:-----------------------|:---------|:--------|
| Shell mode: | interactive | Default: | on | | Shell mode: | interactive | Default: | on |
Allow [commenting](/scripting/basics#comments) in interactive shells, on Allow [commenting](/scripting/basics.md#comments) in interactive shells, on
by default. by default.
### lastpipe ### lastpipe
@ -505,5 +505,5 @@ parsed:
## See also ## See also
- Internal: [shopt builtin command](/commands/builtin/shopt) - Internal: [shopt builtin command](/commands/builtin/shopt.md)
- Internal: [set builtin command](/commands/builtin/set) - Internal: [set builtin command](/commands/builtin/set.md)

View File

@ -67,7 +67,7 @@ conforming to the POSIX(r) standard as well. The profile files read are
`/etc/profile` and `~/.profile`, if it's a login shell. `/etc/profile` and `~/.profile`, if it's a login shell.
If it's not a login shell, the environment variable If it's not a login shell, the environment variable
[ENV](/syntax/shellvars#ENV) is evaluated and the resulting filename is [ENV](/syntax/shellvars.md#ENV) is evaluated and the resulting filename is
used as the name of the startup file. used as the name of the startup file.
After the startup files are read, Bash enters the [POSIX(r) compatiblity After the startup files are read, Bash enters the [POSIX(r) compatiblity
@ -83,7 +83,7 @@ mode (for running, not for starting!)](#posix_run_mode).
When Bash is started in POSIX(r) mode, it follows the POSIX(r) standard When Bash is started in POSIX(r) mode, it follows the POSIX(r) standard
for startup files. In this mode, **interactive shells** expand the for startup files. In this mode, **interactive shells** expand the
[ENV](/syntax/shellvars#ENV) variable and commands are read and executed [ENV](/syntax/shellvars.md#ENV) variable and commands are read and executed
from the file whose name is the expanded value. from the file whose name is the expanded value.
No other startup files are read. Hence, a non-interactive shell doesn't No other startup files are read. Hence, a non-interactive shell doesn't
read any startup files in POSIX(r) mode. read any startup files in POSIX(r) mode.
@ -92,7 +92,7 @@ read any startup files in POSIX(r) mode.
- the commandline option `--posix` is specified - the commandline option `--posix` is specified
- the environment variable - the environment variable
[POSIXLY_CORRECT](/syntax/shellvars#POSIXLY_CORRECT) is set [POSIXLY_CORRECT](/syntax/shellvars.md#POSIXLY_CORRECT) is set
### Quick startup file reference ### Quick startup file reference
@ -301,12 +301,12 @@ FIXME help me to find out what breaks in POSIX(r) mode!
- Bash starting as `sh` (the basename of `argv[0]` is `sh`) - Bash starting as `sh` (the basename of `argv[0]` is `sh`)
- starting Bash with the commandline option `--posix` - starting Bash with the commandline option `--posix`
- on startup, the environment variable - on startup, the environment variable
[POSIXLY_CORRECT](/syntax/shellvars#POSIXLY_CORRECT) is set [POSIXLY_CORRECT](/syntax/shellvars.md#POSIXLY_CORRECT) is set
- the command `set -o posix` - the command `set -o posix`
<u>**Tests for the POSIX(r) mode:**</u> <u>**Tests for the POSIX(r) mode:**</u>
- the variable [SHELLOPTS](/syntax/shellvars#SHELLOPTS) contains `posix` - the variable [SHELLOPTS](/syntax/shellvars.md#SHELLOPTS) contains `posix`
in its list in its list
### Restricted shell ### Restricted shell
@ -316,9 +316,9 @@ far more controlled and limited than the standard shell mode. It acts
like normal Bash with the following restrictions: like normal Bash with the following restrictions:
- the `cd` command can't be used to change directories - the `cd` command can't be used to change directories
- the variables [SHELL](/syntax/shellvars#SHELL), - the variables [SHELL](/syntax/shellvars.md#SHELL),
[PATH](/syntax/shellvars#PATH), [ENV](/syntax/shellvars#ENV) and [PATH](/syntax/shellvars.md#PATH), [ENV](/syntax/shellvars.md#ENV) and
[BASH_ENV](/syntax/shellvars#BASH_ENV) can't be set or unset [BASH_ENV](/syntax/shellvars.md#BASH_ENV) can't be set or unset
- command names that contain a `/` (slash) can't be called (hence you're - command names that contain a `/` (slash) can't be called (hence you're
limited to `PATH`) limited to `PATH`)
- filenames containing a `/` (slash) can't be specified as argument to - filenames containing a `/` (slash) can't be specified as argument to
@ -327,7 +327,7 @@ like normal Bash with the following restrictions:
the `-p` option of the `hash` builtin command the `-p` option of the `hash` builtin command
- function definitions are not inherited from the environment at shell - function definitions are not inherited from the environment at shell
startup startup
- the environment variable [SHELLOPTS](/syntax/shellvars#SHELLOPTS) is - the environment variable [SHELLOPTS](/syntax/shellvars.md#SHELLOPTS) is
ignored at startup ignored at startup
- redirecting output using the `>`, `>|`, `<>`, `>&`, `&>`, and `>>` - redirecting output using the `>`, `>|`, `<>`, `>&`, `&>`, and `>>`
redirection operators isn't allowed redirection operators isn't allowed

View File

@ -19,8 +19,8 @@ Note that the `shopt` builtin command first appeared in Bash 2.0.
For this topic, see also For this topic, see also
- [shell_options](/internals/shell_options) - [shell_options](/internals/shell_options.md)
- [set](/commands/builtin/set) - [set](/commands/builtin/set.md)
| Feature or change description | Appeared in Bash version | See also/remarks | | Feature or change description | Appeared in Bash version | See also/remarks |
|:--------------------------------|:-------------------------|:--------------------------------------------------------------------------------| |:--------------------------------|:-------------------------|:--------------------------------------------------------------------------------|
@ -77,7 +77,7 @@ For this topic, see also
For this topic, see also For this topic, see also
- [printf](/commands/builtin/printf) - [printf](/commands/builtin/printf.md)
| Feature or change description | Appeared in Bash version | See also/remarks | | Feature or change description | Appeared in Bash version | See also/remarks |
|:------------------------------------------------------------|:-------------------------|:-------------------------------------------------------| |:------------------------------------------------------------|:-------------------------|:-------------------------------------------------------|
@ -98,8 +98,8 @@ For this topic, see also
For this topic, see also For this topic, see also
- [conditional_expression](/syntax/ccmd/conditional_expression) - [conditional_expression](/syntax/ccmd/conditional_expression.md)
- [classictest](/commands/classictest) - [classictest](/commands/classictest.md)
| Feature or change description | Appeared in Bash version | See also/remarks | | Feature or change description | Appeared in Bash version | See also/remarks |
|:-------------------------------------------------------------------|:-------------------------|:-------------------------------------------------------------------------------------| |:-------------------------------------------------------------------|:-------------------------|:-------------------------------------------------------------------------------------|
@ -121,23 +121,23 @@ For this topic, see also
| `bashbug` | new | 1.14.0 | | | `bashbug` | new | 1.14.0 | |
| `select` | new | 1.14.0 | | | `select` | new | 1.14.0 | |
| `disown` | new | 2.0 | | | `disown` | new | 2.0 | |
| `shopt` | new | 2.0 | [shopt](/commands/builtin/shopt) | | `shopt` | new | 2.0 | [shopt](/commands/builtin/shopt.md) |
| `declare` | new options `-a` and `-F` | 2.0 | | | `declare` | new options `-a` and `-F` | 2.0 | |
| `enable` | builtin has basic plugin support (dlopen) | 2.0 | | | `enable` | builtin has basic plugin support (dlopen) | 2.0 | |
| `exec` | options `-l`, `-c` and `-a` | 2.0 | | | `exec` | options `-l`, `-c` and `-a` | 2.0 | |
| `read` | options `-p`, `-e` and `-a` | 2.0 | [read](/commands/builtin/read) | | `read` | options `-p`, `-e` and `-a` | 2.0 | [read](/commands/builtin/read.md) |
| `readonly` | option `-a` | 2.0 | [arrays](/syntax/arrays) | | `readonly` | option `-a` | 2.0 | [arrays](/syntax/arrays.md) |
| `time` | new keyword | 2.0 | | | `time` | new keyword | 2.0 | |
| `shopt` | `-p` (reusable output) | 2.02 | | | `shopt` | `-p` (reusable output) | 2.02 | |
| `umask` | `-p` (reusable output) | 2.02 | | | `umask` | `-p` (reusable output) | 2.02 | |
| `complete` | new | 2.04-devel | for and together with support for programmable completion | | `complete` | new | 2.04-devel | for and together with support for programmable completion |
| `compgen` | new | 2.04-devel | for and together with support for programmable completion | | `compgen` | new | 2.04-devel | for and together with support for programmable completion |
| `read` | options `-t`, `-n`, `-d`, `-s` | 2.04-devel | [read](/commands/builtin/read) | | `read` | options `-t`, `-n`, `-d`, `-s` | 2.04-devel | [read](/commands/builtin/read.md) |
| `for ((...;...;...))` | new | 2.04-devel | KSH93 | | `for ((...;...;...))` | new | 2.04-devel | KSH93 |
| `set` | print shell functions in a format reusable as input | 2.05-beta1 | | | `set` | print shell functions in a format reusable as input | 2.05-beta1 | |
| `for` | allow an empty word list | 2.05a-alpha1 | | | `for` | allow an empty word list | 2.05a-alpha1 | |
| `read` | new option `-u` | 2.05b-alpha1 | [read](/commands/builtin/read) | | `read` | new option `-u` | 2.05b-alpha1 | [read](/commands/builtin/read.md) |
| `caller` | new | 3.0 | [caller](/commands/builtin/caller) | | `caller` | new | 3.0 | [caller](/commands/builtin/caller.md) |
| `coproc` | new | 4.0-alpha | | | `coproc` | new | 4.0-alpha | |
| `declare` | new options `-l` and `-u` | 4.0-alpha | together with case-changing expansion forms | | `declare` | new options `-l` and `-u` | 4.0-alpha | together with case-changing expansion forms |
| `case` | new action list terminators '';;& and '';& | 4.0-alpha | ksh93: only `;&`. zsh and mksh: `;|`. mksh: all 4, (`;;&` is undocumented Bash compatibility) | | `case` | new action list terminators '';;& and '';& | 4.0-alpha | ksh93: only `;&`. zsh and mksh: `;|`. mksh: all 4, (`;;&` is undocumented Bash compatibility) |
@ -241,7 +241,7 @@ For this topic, see also
For this topic, see also For this topic, see also
- [pe](/syntax/pe). - [pe](/syntax/pe.md).
| Feature or change description | Appeared in Bash version | Remarks | | Feature or change description | Appeared in Bash version | Remarks |
|:-----------------------------------------------------------------------------------------------------|:-------------------------|:--------------------------------------------------------------------------------------------------------------| |:-----------------------------------------------------------------------------------------------------|:-------------------------|:--------------------------------------------------------------------------------------------------------------|
@ -282,8 +282,8 @@ For this topic, see also
For this topic, see also For this topic, see also
- [arith_expr](/syntax/arith_expr) - [arith_expr](/syntax/arith_expr.md)
- [arith](/syntax/expansion/arith) - [arith](/syntax/expansion/arith.md)
| Feature or change description | Appeared in Bash version | Remarks | | Feature or change description | Appeared in Bash version | Remarks |
|:-------------------------------------------|:-------------------------|:------------------------------------------| |:-------------------------------------------|:-------------------------|:------------------------------------------|
@ -299,7 +299,7 @@ For this topic, see also
For this topic, see also For this topic, see also
- [redirection](/syntax/redirection) - [redirection](/syntax/redirection.md)
| Feature or change description | Appeared in Bash version | Remarks | | Feature or change description | Appeared in Bash version | Remarks |
|:--------------------------------------------------------------------------------------|:-------------------------|:--------| |:--------------------------------------------------------------------------------------|:-------------------------|:--------|

View File

@ -71,7 +71,7 @@ specified by the shebang. \</WRAP\>
**Additional note:** When you specify `#!/bin/sh` as shebang and that's **Additional note:** When you specify `#!/bin/sh` as shebang and that's
a link to a Bash, then Bash will run in POSIX(r) mode! See: a link to a Bash, then Bash will run in POSIX(r) mode! See:
- [Bash behaviour](/scripting/bashbehaviour). - [Bash behaviour](/scripting/bashbehaviour.md).
A common method is to specify a shebang like A common method is to specify a shebang like
@ -113,7 +113,7 @@ When you write a script:
To learn more about the standard filedescriptors, especially about To learn more about the standard filedescriptors, especially about
redirection and piping, see: redirection and piping, see:
- [An illustrated redirection tutorial](/howto/redirection_tutorial) - [An illustrated redirection tutorial](/howto/redirection_tutorial.md)
## Variable names ## Variable names
@ -183,7 +183,7 @@ else
fi fi
``` ```
Read more about [the test command](/commands/classictest) Read more about [the test command](/commands/classictest.md)
A common exit code check method uses the "`||`" or "`&&`" operators. A common exit code check method uses the "`||`" or "`&&`" operators.
This lets you execute a command based on whether or not the previous This lets you execute a command based on whether or not the previous
@ -246,7 +246,7 @@ effectively, the entire block was ignored.
The here-document-tag was quoted here **to avoid substitutions** in the The here-document-tag was quoted here **to avoid substitutions** in the
"commented" text! Check [redirection with "commented" text! Check [redirection with
here-documents](/syntax/redirection#tag_heredoc) for more here-documents](/syntax/redirection.md#tag_heredoc) for more
## Variable scope ## Variable scope
@ -277,7 +277,7 @@ everywhere in that script, both in functions and in the "main program".
example a *subshell*, they will be set there, but you will **never** example a *subshell*, they will be set there, but you will **never**
have access to them outside of that subshell. One way to create a have access to them outside of that subshell. One way to create a
subshell is the pipe. It's all mentioned in a small article about [Bash subshell is the pipe. It's all mentioned in a small article about [Bash
in the processtree](/scripting/processtree)! in the processtree](/scripting/processtree.md)!
### Local variables ### Local variables

View File

@ -55,13 +55,13 @@ Insert **echos** everywhere you can, and print to `stderr`:
echo "DEBUG: current i=$i" >&2 echo "DEBUG: current i=$i" >&2
If you read input from **anywhere**, such as a file or [command If you read input from **anywhere**, such as a file or [command
substitution](/syntax/expansion/cmdsubst), print the debug output with substitution](/syntax/expansion/cmdsubst.md), print the debug output with
literal quotes, to see leading and trailing spaces! literal quotes, to see leading and trailing spaces!
pid=$(< fooservice.pid) pid=$(< fooservice.pid)
echo "DEBUG: read from file: pid=\"$pid\"" >&2 echo "DEBUG: read from file: pid=\"$pid\"" >&2
Bash's [printf](/commands/builtin/printf) command has the `%q` format, Bash's [printf](/commands/builtin/printf.md) command has the `%q` format,
which is handy for verifying whether strings are what they appear to be. which is handy for verifying whether strings are what they appear to be.
foo=$(< inputfile) foo=$(< inputfile)
@ -77,17 +77,17 @@ There are two useful debug outputs for that task (both are written to
- print commands to be executed to `stderr` as if they were read from - print commands to be executed to `stderr` as if they were read from
input (script file or keyboard) input (script file or keyboard)
- print everything **before** any ([substitution and - print everything **before** any ([substitution and
expansion](/syntax/expansion/intro), ...) is applied expansion](/syntax/expansion/intro.md), ...) is applied
- `set -x` mode (`set -o xtrace`) - `set -x` mode (`set -o xtrace`)
- print everything as if it were executed, after [substitution and - print everything as if it were executed, after [substitution and
expansion](/syntax/expansion/intro) is applied expansion](/syntax/expansion/intro.md) is applied
- indicate the depth-level of the subshell (by default by prefixing a - indicate the depth-level of the subshell (by default by prefixing a
`+` (plus) sign to the displayed command) `+` (plus) sign to the displayed command)
- indicate the recognized words after [word - indicate the recognized words after [word
splitting](/syntax/expansion/wordsplit) by marking them like `'x y'` splitting](/syntax/expansion/wordsplit.md) by marking them like `'x y'`
- in shell version 4.1, this debug output can be printed to a - in shell version 4.1, this debug output can be printed to a
configurable file descriptor, rather than sdtout by setting the configurable file descriptor, rather than sdtout by setting the
[BASH_XTRACEFD](/syntax/shellvars#BASH_XTRACEFD) variable. [BASH_XTRACEFD](/syntax/shellvars.md#BASH_XTRACEFD) variable.
**<u>Hint:</u>** These modes can be entered when calling Bash: **<u>Hint:</u>** These modes can be entered when calling Bash:
@ -97,7 +97,7 @@ There are two useful debug outputs for that task (both are written to
### Simple example of how to interpret xtrace output ### Simple example of how to interpret xtrace output
Here's a simple command (a string comparison using the [classic test Here's a simple command (a string comparison using the [classic test
command](/commands/classictest)) executed while in `set -x` mode: command](/commands/classictest.md)) executed while in `set -x` mode:
set -x set -x
foo="bar baz" foo="bar baz"
@ -125,7 +125,7 @@ words (which you would have realized if you READ THE ERROR MESSAGES ;)
(by AnMaster) (by AnMaster)
`xtrace` output would be more useful if it contained source file and `xtrace` output would be more useful if it contained source file and
line number. Add this assignment [PS4](/syntax/shellvars#PS4) at the line number. Add this assignment [PS4](/syntax/shellvars.md#PS4) at the
beginning of your script to enable the inclusion of that information: beginning of your script to enable the inclusion of that information:
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
@ -219,7 +219,7 @@ This can be wrapped in a shell function for more readable code.
Usually indicates exactly what it says: An unexpected end of file. It's Usually indicates exactly what it says: An unexpected end of file. It's
unexpected because Bash waits for the closing of a [compound unexpected because Bash waits for the closing of a [compound
command](/syntax/ccmd/intro): command](/syntax/ccmd/intro.md):
- did you close your `do` with a `done`? - did you close your `do` with a `done`?
- did you close your `if` with a `fi`? - did you close your `if` with a `fi`?
@ -230,7 +230,7 @@ command](/syntax/ccmd/intro):
**<u>Note:</u>** It seems that here-documents (tested on versions **<u>Note:</u>** It seems that here-documents (tested on versions
`1.14.7`, `2.05b`, `3.1.17` and `4.0`) are correctly terminated when `1.14.7`, `2.05b`, `3.1.17` and `4.0`) are correctly terminated when
there is an EOF before the end-of-here-document tag (see there is an EOF before the end-of-here-document tag (see
[redirection](/syntax/redirection)). The reason is unknown, but it seems [redirection](/syntax/redirection.md)). The reason is unknown, but it seems
to be deliberate. Bash 4.0 added an extra message for this: to be deliberate. Bash 4.0 added an extra message for this:
`` warning: here-document at line <N> delimited by end-of-file (wanted `<MARKER>') `` `` warning: here-document at line <N> delimited by end-of-file (wanted `<MARKER>') ``
@ -246,7 +246,7 @@ These *unmatched errors* occur with:
- double-quote pairs - double-quote pairs
- single-quote pairs (also `$'string'`!) - single-quote pairs (also `$'string'`!)
- missing a closing `}` with [parameter expansion syntax](/syntax/pe) - missing a closing `}` with [parameter expansion syntax](/syntax/pe.md)
### Too many arguments ### Too many arguments
@ -365,7 +365,7 @@ the possibility that`^M` is involved. Find and eliminate it! |
## See also ## See also
- [the set builtin command](/commands/builtin/set) (for `-v` and `-x`) - [the set builtin command](/commands/builtin/set.md) (for `-v` and `-x`)
FIXME FIXME

View File

@ -24,8 +24,8 @@ them with <u>Bash</u>, and run them with Bash in <u>native mode</u>.
See also: See also:
- [Bash startup mode: SH mode](/scripting/bashbehaviour#sh_mode) - [Bash startup mode: SH mode](/scripting/bashbehaviour.md#sh_mode)
- [Bash run mode: POSIX mode](/scripting/bashbehaviour#posix_run_mode) - [Bash run mode: POSIX mode](/scripting/bashbehaviour.md#posix_run_mode)
### Your script named "test" doesn't execute ### Your script named "test" doesn't execute
@ -62,7 +62,7 @@ filename expansion happens **after** that, so there is a chance that
Please see: Please see:
- [brace](/syntax/expansion/brace) - [brace](/syntax/expansion/brace.md)
## Test-command ## Test-command
@ -73,7 +73,7 @@ Please see:
Please see: Please see:
- [The classic test command - - [The classic test command -
pitfalls](/commands/classictest#pitfalls_summarized) pitfalls](/commands/classictest.md#pitfalls_summarized)
## Variables ## Variables
@ -161,7 +161,7 @@ of the referenced variables/parameters. i.e. **not** (`$PATH`):
echo "The first character of PATH is ${PATH:0:1}" echo "The first character of PATH is ${PATH:0:1}"
Note that if you are using variables in [arithmetic Note that if you are using variables in [arithmetic
expressions](/syntax/arith_expr), then the bare **name** is allowed: expressions](/syntax/arith_expr.md), then the bare **name** is allowed:
((a=$a+7)) # Add 7 to a ((a=$a+7)) # Add 7 to a
((a = a + 7)) # Add 7 to a. Identical to the previous command. ((a = a + 7)) # Add 7 to a. Identical to the previous command.
@ -171,10 +171,10 @@ expressions](/syntax/arith_expr), then the bare **name** is allowed:
Please see: Please see:
- [words](/syntax/words) - [words](/syntax/words.md)
- [quoting](/syntax/quoting) - [quoting](/syntax/quoting.md)
- [wordsplit](/syntax/expansion/wordsplit) - [wordsplit](/syntax/expansion/wordsplit.md)
- [pe](/syntax/pe) - [pe](/syntax/pe.md)
### Exporting ### Exporting
@ -204,7 +204,7 @@ In this case, the export command is of no use.
Please see: Please see:
- [processtree](/scripting/processtree) - [processtree](/scripting/processtree.md)
## Exit codes ## Exit codes
@ -240,7 +240,7 @@ you need only a "true/false" exit indication, there's no need for `$?`.
See also: See also:
- [Exit codes](/scripting/basics#exit_codes) - [Exit codes](/scripting/basics.md#exit_codes)
### Output vs. Return Value ### Output vs. Return Value
@ -274,5 +274,5 @@ Make sure you're using the form you intended:
Please see: Please see:
- [intro](/syntax/ccmd/intro) - [intro](/syntax/ccmd/intro.md)
- [cmdsubst](/syntax/expansion/cmdsubst) - [cmdsubst](/syntax/expansion/cmdsubst.md)

View File

@ -8,7 +8,7 @@ syntax, with some extensions and derivations.
If scripts need to be portable, some of the BASH-specific syntax If scripts need to be portable, some of the BASH-specific syntax
elements should be avoided. Others should be avoided for all scripts, elements should be avoided. Others should be avoided for all scripts,
e.g. if there is a corresponding POSIX(r)-compatible syntax (see e.g. if there is a corresponding POSIX(r)-compatible syntax (see
[obsolete](/scripting/obsolete)). [obsolete](/scripting/obsolete.md)).
Some syntax elements have a BASH-specific, and a portable[^1]) pendant. Some syntax elements have a BASH-specific, and a portable[^1]) pendant.
In these cases the portable syntax should be preferred. In these cases the portable syntax should be preferred.
@ -72,7 +72,7 @@ or<br />
<code>test EXPRESSION</code></td> <code>test EXPRESSION</code></td>
<td style="text-align: center;">The Bashish test keyword is reserved by <td style="text-align: center;">The Bashish test keyword is reserved by
POSIX(r), but not defined. Use the old fashioned way with the POSIX(r), but not defined. Use the old fashioned way with the
<code>test</code> command. See <a href="/commands/classictest">the <code>test</code> command. See <a href="/commands/classictest.md">the
classic test command</a></td> classic test command</a></td>
<td style="text-align: center;">POSIX(r) and others</td> <td style="text-align: center;">POSIX(r) and others</td>
</tr> </tr>
@ -159,7 +159,7 @@ Why? (list of known behaviours)
variables or the build options, especially KSH93 and Bash) variables or the build options, especially KSH93 and Bash)
For these, and possibly other, reasons, POSIX (SUS) standardized the For these, and possibly other, reasons, POSIX (SUS) standardized the
existance of [the `printf` command](/commands/builtin/printf). existance of [the `printf` command](/commands/builtin/printf.md).
### Parameter expansions ### Parameter expansions
@ -173,7 +173,7 @@ existance of [the `printf` command](/commands/builtin/printf).
#### PWD #### PWD
[PWD](/syntax/shellvars#PWD) is POSIX but not Bourne. Most shells are [PWD](/syntax/shellvars.md#PWD) is POSIX but not Bourne. Most shells are
*not POSIX* in that they don't ignore the value of the `PWD` environment *not POSIX* in that they don't ignore the value of the `PWD` environment
variable. Workaround to fix the value of `PWD` at the start of your variable. Workaround to fix the value of `PWD` at the start of your
script: script:
@ -182,7 +182,7 @@ script:
#### RANDOM #### RANDOM
[RANDOM](/syntax/shellvars#RANDOM) is Bash/KSH/ZSH specific variable [RANDOM](/syntax/shellvars.md#RANDOM) is Bash/KSH/ZSH specific variable
that will give you a random number up to 32767 (2^15-1). Among many that will give you a random number up to 32767 (2^15-1). Among many
other available external options, you can use awk to generate a random other available external options, you can use awk to generate a random
number. There are multiple implementations of awk and which version your number. There are multiple implementations of awk and which version your
@ -208,12 +208,12 @@ complaining about possible stupid code!*
#### SECONDS #### SECONDS
[SECONDS](/syntax/shellvars#SECONDS) is KSH/ZSH/Bash specific. Avoid it. [SECONDS](/syntax/shellvars.md#SECONDS) is KSH/ZSH/Bash specific. Avoid it.
Find another method. Find another method.
### Check for a command in PATH ### Check for a command in PATH
The [PATH](/syntax/shellvars#PATH) variable is a colon-delimited list of The [PATH](/syntax/shellvars.md#PATH) variable is a colon-delimited list of
directory names, so it's basically possible to run a loop and check directory names, so it's basically possible to run a loop and check
every `PATH` component for the command you're looking for and for every `PATH` component for the command you're looking for and for
executability. executability.

View File

@ -10,12 +10,12 @@ parameters are described below:
| Parameter(s) | Description | | Parameter(s) | Description |
|------------------|---------------------------------------------------------------------------------------------------------------------------------| |------------------|---------------------------------------------------------------------------------------------------------------------------------|
| `$0` | the first positional parameter, equivalent to `argv[0]` in C, see [the first argument](/scripting/posparams#the_first_argument) | | `$0` | the first positional parameter, equivalent to `argv[0]` in C, see [the first argument](/scripting/posparams.md#the_first_argument) |
| `$FUNCNAME` | the function name (<u>**attention**</u>: inside a function, `$0` is still the `$0` of the shell, **not** the function name) | | `$FUNCNAME` | the function name (<u>**attention**</u>: inside a function, `$0` is still the `$0` of the shell, **not** the function name) |
| `$1 ... $9` | the argument list elements from 1 to 9 | | `$1 ... $9` | the argument list elements from 1 to 9 |
| `${10} ... ${N}` | the argument list elements beyond 9 (note the [parameter expansion](/syntax/pe) syntax!) | | `${10} ... ${N}` | the argument list elements beyond 9 (note the [parameter expansion](/syntax/pe.md) syntax!) |
| `$*` | all positional parameters except `$0`, see [mass usage](/scripting/posparams#mass_usage) | | `$*` | all positional parameters except `$0`, see [mass usage](/scripting/posparams.md#mass_usage) |
| `$@` | all positional parameters except `$0`, see [mass usage](/scripting/posparams#mass_usage) | | `$@` | all positional parameters except `$0`, see [mass usage](/scripting/posparams.md#mass_usage) |
| `$#` | the number of arguments, not counting `$0` | | `$#` | the number of arguments, not counting `$0` |
These positional parameters reflect exactly what was given to the script These positional parameters reflect exactly what was given to the script
@ -104,7 +104,7 @@ There are several ways to loop through the positional parameters.
------------------------------------------------------------------------ ------------------------------------------------------------------------
You can code a [C-style for-loop](/syntax/ccmd/c_for) using `$#` as the You can code a [C-style for-loop](/syntax/ccmd/c_for.md) using `$#` as the
end value. On every iteration, the `shift`-command is used to shift the end value. On every iteration, the `shift`-command is used to shift the
argument list: argument list:
@ -135,7 +135,7 @@ a given wordlist. The loop uses the positional parameters as a wordlist:
The next method is similar to the first example (the `for` loop), but it The next method is similar to the first example (the `for` loop), but it
doesn't test for reaching `$#`. It shifts and checks if `$1` still doesn't test for reaching `$#`. It shifts and checks if `$1` still
expands to something, using the [test command](/commands/classictest): expands to something, using the [test command](/commands/classictest.md):
while [ "$1" ] while [ "$1" ]
do do
@ -146,7 +146,7 @@ expands to something, using the [test command](/commands/classictest):
Looks nice, but has the disadvantage of stopping when `$1` is empty Looks nice, but has the disadvantage of stopping when `$1` is empty
(null-string). Let's modify it to run as long as `$1` is defined (but (null-string). Let's modify it to run as long as `$1` is defined (but
may be null), using [parameter expansion for an alternate may be null), using [parameter expansion for an alternate
value](/syntax/pe#use_an_alternate_value): value](/syntax/pe.md#use_an_alternate_value):
while [ "${1+defined}" ]; do while [ "${1+defined}" ]; do
echo "$1" echo "$1"
@ -156,7 +156,7 @@ value](/syntax/pe#use_an_alternate_value):
### Getopts ### Getopts
There is a [small tutorial dedicated to There is a [small tutorial dedicated to
`getopts`](/howto/getopts_tutorial) (*under construction*). `getopts`](/howto/getopts_tutorial.md) (*under construction*).
## Mass usage ## Mass usage
@ -202,8 +202,8 @@ Well, let's just say: **You almost always want a quoted `"$@"`!**
Another way to mass expand the positional parameters is similar to what Another way to mass expand the positional parameters is similar to what
is possible for a range of characters using [substring is possible for a range of characters using [substring
expansion](/syntax/pe#substring_expansion) on normal parameters and the expansion](/syntax/pe.md#substring_expansion) on normal parameters and the
mass expansion range of [arrays](/syntax/arrays). mass expansion range of [arrays](/syntax/arrays.md).
`${@:START:COUNT}` `${@:START:COUNT}`
@ -236,7 +236,7 @@ when the positional parameters are in use. A `START` of `1` begins at
## Setting Positional Parameters ## Setting Positional Parameters
Setting positional parameters with command line arguments, is not the Setting positional parameters with command line arguments, is not the
only way to set them. The [builtin command, set](/commands/builtin/set) only way to set them. The [builtin command, set](/commands/builtin/set.md)
may be used to "artificially" change the positional parameters from may be used to "artificially" change the positional parameters from
inside the script or function: inside the script or function:
@ -381,16 +381,16 @@ options" for `ls` and doesn't change anything after it:
### Using getopts ### Using getopts
There is a [small tutorial dedicated to There is a [small tutorial dedicated to
`getopts`](/howto/getopts_tutorial) (*under construction*). `getopts`](/howto/getopts_tutorial.md) (*under construction*).
## See also ## See also
- Internal: [getopts_tutorial](/howto/getopts_tutorial) - Internal: [getopts_tutorial](/howto/getopts_tutorial.md)
- Internal: [while_loop](/syntax/ccmd/while_loop) - Internal: [while_loop](/syntax/ccmd/while_loop.md)
- Internal: [c_for](/syntax/ccmd/c_for) - Internal: [c_for](/syntax/ccmd/c_for.md)
- Internal: [arrays](/syntax/arrays) (for equivalent syntax for - Internal: [arrays](/syntax/arrays.md) (for equivalent syntax for
mass-expansion) mass-expansion)
- Internal: [Substring expansion on a - Internal: [Substring expansion on a
parameter](/syntax/pe#substring_expansion) (for equivalent syntax for parameter](/syntax/pe.md#substring_expansion) (for equivalent syntax for
mass-expansion) mass-expansion)
- Dictionary, internal: [parameter](/dict/terms/parameter) - Dictionary, internal: [parameter](/dict/terms/parameter)

View File

@ -25,8 +25,8 @@ into the environment with the bash builtin command `export`:
export MYVAR export MYVAR
Common system variables like [PATH](/syntax/shellvars#PATH) or Common system variables like [PATH](/syntax/shellvars.md#PATH) or
[HOME](/syntax/shellvars#HOME) are usually part of the environment (as [HOME](/syntax/shellvars.md#HOME) are usually part of the environment (as
set by login scripts or programs). set by login scripts or programs).
## Executing programs ## Executing programs
@ -161,7 +161,7 @@ are run inside a subshell:
### Command substitution ### Command substitution
With [command substitution](/syntax/expansion/cmdsubst) you re-use the With [command substitution](/syntax/expansion/cmdsubst.md) you re-use the
output of another command as text in your command line, for example to output of another command as text in your command line, for example to
set a variable. The other command is run in a subshell: set a variable. The other command is run in a subshell:

View File

@ -33,7 +33,7 @@ many may prefer 4 spaces, see below in the discussion section):
Speaking of hard-tabs: Avoid them if possible. They only make trouble. I Speaking of hard-tabs: Avoid them if possible. They only make trouble. I
can imagine one case where they're useful: Indenting can imagine one case where they're useful: Indenting
[here-documents](/syntax/redirection#here_documents). [here-documents](/syntax/redirection.md#here_documents).
### Breaking up lines ### Breaking up lines
@ -55,7 +55,7 @@ supports the visual impression of "these belong together".
### Breaking compound commands ### Breaking compound commands
[Compound commands](/syntax/ccmd/intro) form the structures that make a [Compound commands](/syntax/ccmd/intro.md) form the structures that make a
shell script different from a stupid enumeration of commands. Usually shell script different from a stupid enumeration of commands. Usually
they contain a kind of "head" and a "body" that contains command lists. they contain a kind of "head" and a "body" that contains command lists.
This type of compound command is relatively easy to indent. This type of compound command is relatively easy to indent.
@ -241,7 +241,7 @@ Bash, but is not a good idea.
### Command substitution ### Command substitution
As noted in [the article about command As noted in [the article about command
substitution](/syntax/expansion/cmdsubst), you should use the `$( ... )` substitution](/syntax/expansion/cmdsubst.md), you should use the `$( ... )`
form. form.
If portability is a concern, use the backquoted form `` ` ... ` ``. If portability is a concern, use the backquoted form `` ` ... ` ``.
@ -313,7 +313,7 @@ have to ensure they're in a specific order.
The portable form of the function definition should be used, without the The portable form of the function definition should be used, without the
`function` keyword (here using the [grouping compound `function` keyword (here using the [grouping compound
command](/syntax/ccmd/grouping_plain)): command](/syntax/ccmd/grouping_plain.md)):
getargs() { getargs() {
... ...

View File

@ -225,27 +225,27 @@ Some stuff I didn't like there:
- uses external, unreliable command `which` instead of builtin `type -p` - uses external, unreliable command `which` instead of builtin `type -p`
to determinate the location of a program to determinate the location of a program
- lacks [sane quoting](/syntax/quoting) - lacks [sane quoting](/syntax/quoting.md)
- uses `function SOMENAME` keyword instead of the common - uses `function SOMENAME` keyword instead of the common
POSIX-compatible variant `SOMENAME()` to [define a POSIX-compatible variant `SOMENAME()` to [define a
function](/syntax/basicgrammar#shell_function_definitions) function](/syntax/basicgrammar.md#shell_function_definitions)
- uses backticks instead of `$( ... )` for [command - uses backticks instead of `$( ... )` for [command
substitution](/syntax/expansion/cmdsubst) substitution](/syntax/expansion/cmdsubst.md)
- incorrectly uses an additional array to store [positional - incorrectly uses an additional array to store [positional
parameters](/scripting/posparams), disregarding that `$@` already is parameters](/scripting/posparams.md), disregarding that `$@` already is
array-like array-like
- uses `echo -e` and the historical control character `\c` instead of - uses `echo -e` and the historical control character `\c` instead of
modern [printf](/commands/builtin/printf) modern [printf](/commands/builtin/printf.md)
- uses `` for a in `seq 1 10` `` instead of a [C-like counter - uses `` for a in `seq 1 10` `` instead of a [C-like counter
loop](/syntax/ccmd/c_for) `for ((a=1; a <= 10; a++))` loop](/syntax/ccmd/c_for.md) `for ((a=1; a <= 10; a++))`
- the `if/else` stuff looks as if the `test` (or `[ ...]`) command is - the `if/else` stuff looks as if the `test` (or `[ ...]`) command is
the only thing Bash can execute and check the only thing Bash can execute and check
- a `for` loop example that **will** explode on - a `for` loop example that **will** explode on
[word-splitting](/syntax/expansion/wordsplit) [word-splitting](/syntax/expansion/wordsplit.md)
- arithmetic tests (the while/until loop examples) using the historical - arithmetic tests (the while/until loop examples) using the historical
"old way" with `test`, not [modern arithmetic "old way" with `test`, not [modern arithmetic
components](/syntax/arith_expr) components](/syntax/arith_expr.md)
- useless [quoting](/syntax/quoting) of one-word strings (not that it - useless [quoting](/syntax/quoting.md) of one-word strings (not that it
hurts per se, but it shows that the author has no clue when to use hurts per se, but it shows that the author has no clue when to use
quotes) quotes)
- a weird construct I don't understand (example for stdout/err - a weird construct I don't understand (example for stdout/err
@ -274,7 +274,7 @@ learning tutorial - but that is not the goal.
One point (I **have** to criticize **something** ;-) ): One point (I **have** to criticize **something** ;-) ):
- the article says that there are no [C-styled - the article says that there are no [C-styled
for-loops](/syntax/ccmd/c_for) in Bash, this is wrong (maybe the for-loops](/syntax/ccmd/c_for.md) in Bash, this is wrong (maybe the
article is for a very old (pre `2.05b`) Bash version) article is for a very old (pre `2.05b`) Bash version)
\<BOOKMARK:rv_bprogintrohowto\> \<BOOKMARK:rv_bprogintrohowto\>
@ -288,14 +288,14 @@ A few points:
- uses `function SOMENAME` instead of more common and most portable - uses `function SOMENAME` instead of more common and most portable
`SOMENAME()` to [define `SOMENAME()` to [define
functions](/syntax/basicgrammar#shell_function_definitions) functions](/syntax/basicgrammar.md#shell_function_definitions)
- wrong description of the [if clause](/syntax/ccmd/if_clause) (says - wrong description of the [if clause](/syntax/ccmd/if_clause.md) (says
"the base \[...\] is `if [expression];`", which is wrong) "the base \[...\] is `if [expression];`", which is wrong)
- a [for-loop example](/syntax/ccmd/classic_for) will explode due to - a [for-loop example](/syntax/ccmd/classic_for.md) will explode due to
[word splitting](/syntax/expansion/wordsplit) (`for i in $( ls )` - [word splitting](/syntax/expansion/wordsplit.md) (`for i in $( ls )` -
evil!) evil!)
- the mentioned C-like for-loop is not the [real C-like - the mentioned C-like for-loop is not the [real C-like
for-loop](/syntax/ccmd/c_for), it just calls `seq(1)`+ for-loop](/syntax/ccmd/c_for.md), it just calls `seq(1)`+
- Many syntax errors: The examples won't even parse correctly - Many syntax errors: The examples won't even parse correctly
I like the style this article is written in. If the points are fixed, it I like the style this article is written in. If the points are fixed, it

View File

@ -12,7 +12,7 @@ tutorial.
## List of snippets ## List of snippets
[reset filter](/snipplets/start) [reset filter](/snipplets/start.md)
---- datacloud snippet ---- field: snipplet_tags ---- datacloud snippet ---- field: snipplet_tags

142
start.md
View File

@ -32,88 +32,88 @@ only there to prevent SPAM.
- [Bash v4 - a rough overview](bash4.md) (unmaintained, since Bash 4 is - [Bash v4 - a rough overview](bash4.md) (unmaintained, since Bash 4 is
more or less standard) more or less standard)
- [style](/scripting/style.md) -- an assorted collection of style and optic - [style](/scripting/style.md.md) -- an assorted collection of style and optic
hints hints
- [basics](/scripting/basics.md) - [basics](/scripting/basics.md.md)
- [newbie_traps](/scripting/newbie_traps.md) - [newbie_traps](/scripting/newbie_traps.md.md)
- [bashbehaviour](/scripting/bashbehaviour.md) - [bashbehaviour](/scripting/bashbehaviour.md.md)
- [posparams](/scripting/posparams.md) - [posparams](/scripting/posparams.md.md)
- [processtree](/scripting/processtree.md) - [processtree](/scripting/processtree.md.md)
- [obsolete](/scripting/obsolete.md) - [obsolete](/scripting/obsolete.md.md)
- [nonportable](/scripting/nonportable.md) - [nonportable](/scripting/nonportable.md.md)
- [debuggingtips](/scripting/debuggingtips.md) - [debuggingtips](/scripting/debuggingtips.md.md)
- [terminalcodes](/scripting/terminalcodes.md) - [terminalcodes](/scripting/terminalcodes.md.md)
- [tutoriallist](/scripting/tutoriallist.md) - [tutoriallist](/scripting/tutoriallist.md.md)
## Code snippets ## Code snippets
There is a [section that holds small code snippets](/snipplets/start.md). There is a [section that holds small code snippets](/snipplets/start.md.md).
See also [some Bash source code excerpts](/misc/readthesourceluke.md). See also [some Bash source code excerpts](/misc/readthesourceluke.md.md).
## How to ## How to
[Doing specific tasks: concepts, methods, ideas](/howto/start.md): [Doing specific tasks: concepts, methods, ideas](/howto/start.md.md):
- [Simple locking (against parallel run)](/howto/mutex.md) - [Simple locking (against parallel run)](/howto/mutex.md.md)
- [Rudimentary config files for your scripts](/howto/conffile.md) - [Rudimentary config files for your scripts](/howto/conffile.md.md)
- [Editing files with ed(1)](/howto/edit-ed.md) - [Editing files with ed(1)](/howto/edit-ed.md.md)
- [Collapsing Functions](/howto/collapsing_functions.md) - [Collapsing Functions](/howto/collapsing_functions.md.md)
- [Illustrated Redirection Tutorial](/howto/redirection_tutorial.md) - [Illustrated Redirection Tutorial](/howto/redirection_tutorial.md.md)
- [Calculate with dc(1)](/howto/calculate-dc.md) - [Calculate with dc(1)](/howto/calculate-dc.md)
- [Introduction to pax - the POSIX archiver](/howto/pax.md) - [Introduction to pax - the POSIX archiver](/howto/pax.md.md)
- [getopts_tutorial](/howto/getopts_tutorial.md) (*under construction!*) - [getopts_tutorial](/howto/getopts_tutorial.md.md) (*under construction!*)
- [dissectabadoneliner](/howto/dissectabadoneliner.md) An example of a bad - [dissectabadoneliner](/howto/dissectabadoneliner.md.md) An example of a bad
oneliner, breakdown and fix (by `kojoro`) oneliner, breakdown and fix (by `kojoro`)
- [Write tests for ./your-script.sh](/howto/testing-your-scripts.md) by - [Write tests for ./your-script.sh](/howto/testing-your-scripts.md.md) by
using bashtest util using bashtest util
## Bash syntax and operations ## Bash syntax and operations
- [Bash features overview by version](/scripting/bashchanges.md) - [Bash features overview by version](/scripting/bashchanges.md.md)
- [Basic grammar rules](/syntax/basicgrammar.md) - [Basic grammar rules](/syntax/basicgrammar.md.md)
- [Quoting and character escaping](/syntax/quoting.md) - [Quoting and character escaping](/syntax/quoting.md.md)
- [Parsing and execution](/syntax/grammar/parser_exec.md) - [Parsing and execution](/syntax/grammar/parser_exec.md.md)
- [Some words about words...](/syntax/words.md) - [Some words about words...](/syntax/words.md.md)
- [Patterns and pattern matching](/syntax/pattern.md) - [Patterns and pattern matching](/syntax/pattern.md.md)
- [Arithmetic expressions](/syntax/arith_expr.md) - [Arithmetic expressions](/syntax/arith_expr.md.md)
- [List of shell options](/internals/shell_options.md) - [List of shell options](/internals/shell_options.md.md)
- [Redirection](/syntax/redirection.md) - [Redirection](/syntax/redirection.md.md)
- [Special parameters and shell variables](/syntax/shellvars.md) - [Special parameters and shell variables](/syntax/shellvars.md.md)
- [Arrays](/syntax/arrays.md) - [Arrays](/syntax/arrays.md.md)
## Compound commands ## Compound commands
| **[Compound commands overview](/syntax/ccmd/intro.md)** | | | **[Compound commands overview](/syntax/ccmd/intro.md.md)** | |
|:-----------------------------------------------------|------------------------------------------------------------------| |:-----------------------------------------------------|------------------------------------------------------------------|
| Grouping | | | Grouping | |
| `{ ...; }` | [command grouping](/syntax/ccmd/grouping_plain.md) | | `{ ...; }` | [command grouping](/syntax/ccmd/grouping_plain.md.md) |
| `( ... )` | [command grouping in a subshell](/syntax/ccmd/grouping_subshell.md) | | `( ... )` | [command grouping in a subshell](/syntax/ccmd/grouping_subshell.md.md) |
| Conditionals | | | Conditionals | |
| `[[ ... ]]` | [conditional expression](/syntax/ccmd/conditional_expression.md) | | `[[ ... ]]` | [conditional expression](/syntax/ccmd/conditional_expression.md.md) |
| `if ...; then ...; fi` | [conditional branching](/syntax/ccmd/if_clause.md) | | `if ...; then ...; fi` | [conditional branching](/syntax/ccmd/if_clause.md.md) |
| `case ... esac` | [pattern-based branching](/syntax/ccmd/case.md) | | `case ... esac` | [pattern-based branching](/syntax/ccmd/case.md.md) |
| Loops | | | Loops | |
| `for word in ...; do ...; done` | [classic for-loop](/syntax/ccmd/classic_for.md) | | `for word in ...; do ...; done` | [classic for-loop](/syntax/ccmd/classic_for.md.md) |
| `for ((x=1; x<=10; x++)); do ...; done` | [C-style for-loop](/syntax/ccmd/c_for.md) | | `for ((x=1; x<=10; x++)); do ...; done` | [C-style for-loop](/syntax/ccmd/c_for.md.md) |
| `while ...; do ...; done` | [while loop](/syntax/ccmd/while_loop.md) | | `while ...; do ...; done` | [while loop](/syntax/ccmd/while_loop.md.md) |
| `until ...; do ...; done` | [until loop](/syntax/ccmd/until_loop.md) | | `until ...; do ...; done` | [until loop](/syntax/ccmd/until_loop.md.md) |
| Misc | | | Misc | |
| `(( ... ))` | [arithmetic evaluation](/syntax/ccmd/arithmetic_eval.md) | | `(( ... ))` | [arithmetic evaluation](/syntax/ccmd/arithmetic_eval.md.md) |
| `select word in ...; do ...; done` | [user selections](/syntax/ccmd/user_select.md) | | `select word in ...; do ...; done` | [user selections](/syntax/ccmd/user_select.md.md) |
## Expansions and substitutions ## Expansions and substitutions
| **[Introduction to expansions and substitutions](/syntax/expansion/intro.md)** | | | **[Introduction to expansions and substitutions](/syntax/expansion/intro.md.md)** | |
|:----------------------------------------------------------------------------|------------------------------------------------------| |:----------------------------------------------------------------------------|------------------------------------------------------|
| `{A,B,C} {A..C}` | [Brace expansion](/syntax/expansion/brace.md) | | `{A,B,C} {A..C}` | [Brace expansion](/syntax/expansion/brace.md.md) |
| `~/ ~root/` | [Tilde expansion](/syntax/expansion/tilde.md) | | `~/ ~root/` | [Tilde expansion](/syntax/expansion/tilde.md.md) |
| `$FOO ${BAR%.mp3}` | [Parameter expansion](/syntax/pe.md) | | `$FOO ${BAR%.mp3}` | [Parameter expansion](/syntax/pe.md.md) |
| `` `command` $(command) `` | [Command substitution](/syntax/expansion/cmdsubst.md) | | `` `command` $(command) `` | [Command substitution](/syntax/expansion/cmdsubst.md.md) |
| `<(command) >(command)` | [Process substitution](/syntax/expansion/proc_subst.md) | | `<(command) >(command)` | [Process substitution](/syntax/expansion/proc_subst.md.md) |
| `$((1 + 2 + 3)) $[4 + 5 + 6]` | [Arithmetic expansion](/syntax/expansion/arith.md) | | `$((1 + 2 + 3)) $[4 + 5 + 6]` | [Arithmetic expansion](/syntax/expansion/arith.md.md) |
| `Hello <---> Word!` | [Word splitting](/syntax/expansion/wordsplit.md) | | `Hello <---> Word!` | [Word splitting](/syntax/expansion/wordsplit.md.md) |
| `/data/*-av/*.mp?` | [Pathname expansion](/syntax/expansion/globs.md) | | `/data/*-av/*.mp?` | [Pathname expansion](/syntax/expansion/globs.md.md) |
## Builtin Commands ## Builtin Commands
@ -137,7 +137,7 @@ datastructures.</th>
<tbody> <tbody>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/declare.md">declare</a></td> href="/commands/builtin/declare.md.md">declare</a></td>
<td>Display or set shell variables or functions along with <td>Display or set shell variables or functions along with
attributes.</td> attributes.</td>
<td style="text-align: center;"><code>typeset</code></td> <td style="text-align: center;"><code>typeset</code></td>
@ -167,14 +167,14 @@ href="/commands/builtin/local">local</a></td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/read.mdonly">readonly</a></td> href="/commands/builtin/read.md.mdonly">readonly</a></td>
<td>Mark variables or functions as read-only.</td> <td>Mark variables or functions as read-only.</td>
<td style="text-align: center;"><code>typeset -r</code></td> <td style="text-align: center;"><code>typeset -r</code></td>
<td style="text-align: center;">special builtin</td> <td style="text-align: center;">special builtin</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/unset.md">unset</a></td> href="/commands/builtin/unset.md.md">unset</a></td>
<td>Unset variables and functions.</td> <td>Unset variables and functions.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
<td style="text-align: center;">special builtin</td> <td style="text-align: center;">special builtin</td>
@ -197,7 +197,7 @@ streams.</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/syntax/keywords/coproc.md">coproc</a></td> href="/syntax/keywords/coproc.md.md">coproc</a></td>
<td>Co-processes: Run a command in the background with pipes for reading <td>Co-processes: Run a command in the background with pipes for reading
/ writing its standard streams.</td> / writing its standard streams.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
@ -212,21 +212,21 @@ href="/commands/builtin/echo">echo</a></td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/mapfile.md">mapfile</a></td> href="/commands/builtin/mapfile.md.md">mapfile</a></td>
<td>Read lines of input into an array.</td> <td>Read lines of input into an array.</td>
<td style="text-align: center;"><code>readarray</code></td> <td style="text-align: center;"><code>readarray</code></td>
<td style="text-align: center;">builtin</td> <td style="text-align: center;">builtin</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/printf.md">printf</a></td> href="/commands/builtin/printf.md.md">printf</a></td>
<td>"advanced <code>echo</code>."</td> <td>"advanced <code>echo</code>."</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
<td style="text-align: center;">builtin</td> <td style="text-align: center;">builtin</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/read.md">read</a></td> href="/commands/builtin/read.md.md">read</a></td>
<td>Read input into variables or arrays, or split strings into fields <td>Read input into variables or arrays, or split strings into fields
using delimiters.</td> using delimiters.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
@ -241,14 +241,14 @@ Commands that modify shell behavior, change special options, assist in debugging
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/caller.md">caller</a></td> href="/commands/builtin/caller.md.md">caller</a></td>
<td>Identify/print execution frames.</td> <td>Identify/print execution frames.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
<td style="text-align: center;">builtin</td> <td style="text-align: center;">builtin</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/set.md">set</a></td> href="/commands/builtin/set.md.md">set</a></td>
<td>Set the positional parameters and/or set options that affect shell <td>Set the positional parameters and/or set options that affect shell
behaviour.</td> behaviour.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
@ -256,7 +256,7 @@ behaviour.</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/shopt.md">shopt</a></td> href="/commands/builtin/shopt.md.md">shopt</a></td>
<td>set/get some bash-specific shell options.</td> <td>set/get some bash-specific shell options.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
<td style="text-align: center;">builtin</td> <td style="text-align: center;">builtin</td>
@ -305,7 +305,7 @@ href="/commands/builtin/continueBreak">continue / break</a></td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/let.md">let</a></td> href="/commands/builtin/let.md.md">let</a></td>
<td>Arithmetic evaluation simple command.</td> <td>Arithmetic evaluation simple command.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
<td style="text-align: center;">builtin</td> <td style="text-align: center;">builtin</td>
@ -319,7 +319,7 @@ href="/commands/builtin/return">return</a></td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/classictest.md">[</a></td> href="/commands/classictest.md.md">[</a></td>
<td>The classic <code>test</code> simple command.</td> <td>The classic <code>test</code> simple command.</td>
<td style="text-align: center;">test</td> <td style="text-align: center;">test</td>
<td style="text-align: center;">builtin</td> <td style="text-align: center;">builtin</td>
@ -334,7 +334,7 @@ signals, process groups, subshells.</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td style="text-align: center;"><a <td style="text-align: center;"><a
href="/commands/builtin/exec.md">exec</a></td> href="/commands/builtin/exec.md.md">exec</a></td>
<td>Replace the current shell process or set redirections.</td> <td>Replace the current shell process or set redirections.</td>
<td style="text-align: center;">-</td> <td style="text-align: center;">-</td>
<td style="text-align: center;">special builtin</td> <td style="text-align: center;">special builtin</td>
@ -385,7 +385,7 @@ href="/commands/builtin/wait">wait</a></td>
## Dictionary ## Dictionary
| :bulb: A list of expressions, words, and their meanings is [here](/dict/index.md). | | :bulb: A list of expressions, words, and their meanings is [here](/dict/index.md.md). |
| --- | | --- |
## Links ## Links
@ -474,7 +474,7 @@ href="/commands/builtin/wait">wait</a></td>
commands](https://www.rosehosting.com/blog/basic-shell-commands-after-putty-ssh-logon/) commands](https://www.rosehosting.com/blog/basic-shell-commands-after-putty-ssh-logon/)
- [Bashphorism list from the Bash IRC channel on - [Bashphorism list from the Bash IRC channel on
Freenode](/misc/bashphorisms) Freenode](/misc/bashphorisms)
- [Some more or less funny commandline stuff](/misc/shell_humor.md) - [Some more or less funny commandline stuff](/misc/shell_humor.md.md)
- [How to Enable SSH on Ubuntu - [How to Enable SSH on Ubuntu
Tutorial](https://thishosting.rocks/how-to-enable-ssh-on-ubuntu/) Tutorial](https://thishosting.rocks/how-to-enable-ssh-on-ubuntu/)
- [How To Make an Awesome Custom Shell with - [How To Make an Awesome Custom Shell with
@ -499,7 +499,7 @@ If you have critiques or suggestions, please feel free to send a mail
using the contact form on the right. Note that there is a simple using the contact form on the right. Note that there is a simple
discussion option below every article. discussion option below every article.
Please also see the [imprint](/user/thebonsai/imprint.md) if you have Please also see the [imprint](/user/thebonsai/imprint.md.md) if you have
problems with the site and its contents (legality, ...)! problems with the site and its contents (legality, ...)!
It also would be nice to drop a line when It also would be nice to drop a line when

View File

@ -4,13 +4,13 @@
Arithmetic expressions are used in several situations: Arithmetic expressions are used in several situations:
- [arithmetic evaluation command](/syntax/ccmd/arithmetic_eval) - [arithmetic evaluation command](/syntax/ccmd/arithmetic_eval.md)
- [arithmetic expansion](/syntax/expansion/arith) - [arithmetic expansion](/syntax/expansion/arith.md)
- [substring parameter expansion](/syntax/pe#substring_expansion) - [substring parameter expansion](/syntax/pe.md#substring_expansion)
- [the `let` builtin command](/commands/builtin/let) - [the `let` builtin command](/commands/builtin/let.md)
- [C-style for loop](/syntax/ccmd/c_for) - [C-style for loop](/syntax/ccmd/c_for.md)
- [array indexing](/syntax/arrays) - [array indexing](/syntax/arrays.md)
- [conditional expressions](/syntax/ccmd/conditional_expression) - [conditional expressions](/syntax/ccmd/conditional_expression.md)
- Assignment statements, and arguments to declaration commands of - Assignment statements, and arguments to declaration commands of
variables with the integer attribute. variables with the integer attribute.
@ -95,7 +95,7 @@ and what numbers are and how they are built, then you don't need
different bases. different bases.
If you want to convert between the usual bases (octal, decimal, hex), If you want to convert between the usual bases (octal, decimal, hex),
use [the printf command](/commands/builtin/printf) and its format use [the printf command](/commands/builtin/printf.md) and its format
strings. strings.
## Shell variables ## Shell variables
@ -121,7 +121,7 @@ When variables are referenced, the notation `1 + $X` is equivalent to
the notation `1 + X`, both are allowed. the notation `1 + X`, both are allowed.
When variables are referenced like `$X`, the rules of [parameter When variables are referenced like `$X`, the rules of [parameter
expansion](/syntax/pe) apply and are performed **before** the expression expansion](/syntax/pe.md) apply and are performed **before** the expression
is evaluated. Thus, a construct like `${MYSTRING:4:3}` is valid inside is evaluated. Thus, a construct like `${MYSTRING:4:3}` is valid inside
an arithmetic expression. an arithmetic expression.
@ -130,7 +130,7 @@ an arithmetic expression.
Unlike command exit and return codes, arithmetic expressions evaluate to Unlike command exit and return codes, arithmetic expressions evaluate to
logical "true" when they are not 0. When they are 0, they evaluate to logical "true" when they are not 0. When they are 0, they evaluate to
"false". The [arithmetic evaluation compound "false". The [arithmetic evaluation compound
command](/syntax/ccmd/arithmetic_eval) reverses the "truth" of an command](/syntax/ccmd/arithmetic_eval.md) reverses the "truth" of an
arithmetic expression to match the "truth" of command exit codes: arithmetic expression to match the "truth" of command exit codes:
- if the arithmetic expression brings up a value not 0 (arithmetic - if the arithmetic expression brings up a value not 0 (arithmetic
@ -153,16 +153,16 @@ That means, the following `if`-clause will execute the `else`-thread:
| Operator | Description | | Operator | Description |
|---------------------|----------------------------------------------------------------------------------------------------| |---------------------|----------------------------------------------------------------------------------------------------|
| `<ID> = <EXPR>` | normal assignment | | `<ID> = <EXPR>` | normal assignment |
| `<ID> *= <EXPR>` | equivalent to `<ID> = <ID> * <EXPR>`, see [calculation operators](/syntax/arith_expr#calculations) | | `<ID> *= <EXPR>` | equivalent to `<ID> = <ID> * <EXPR>`, see [calculation operators](/syntax/arith_expr.md#calculations) |
| `<ID> /= <EXPR>` | equivalent to `<ID> = <ID> / <EXPR>`, see [calculation operators](/syntax/arith_expr#calculations) | | `<ID> /= <EXPR>` | equivalent to `<ID> = <ID> / <EXPR>`, see [calculation operators](/syntax/arith_expr.md#calculations) |
| `<ID> %= <EXPR>` | equivalent to `<ID> = <ID> % <EXPR>`, see [calculation operators](/syntax/arith_expr#calculations) | | `<ID> %= <EXPR>` | equivalent to `<ID> = <ID> % <EXPR>`, see [calculation operators](/syntax/arith_expr.md#calculations) |
| `<ID> += <EXPR>` | equivalent to `<ID> = <ID> + <EXPR>`, see [calculation operators](/syntax/arith_expr#calculations) | | `<ID> += <EXPR>` | equivalent to `<ID> = <ID> + <EXPR>`, see [calculation operators](/syntax/arith_expr.md#calculations) |
| `<ID> -= <EXPR>` | equivalent to `<ID> = <ID> - <EXPR>`, see [calculation operators](/syntax/arith_expr#calculations) | | `<ID> -= <EXPR>` | equivalent to `<ID> = <ID> - <EXPR>`, see [calculation operators](/syntax/arith_expr.md#calculations) |
| `<ID> <<= <NUMBER>` | equivalent to `<ID> = <ID> << <NUMBER>`, see [bit operations](/syntax/arith_expr#bit_operations) | | `<ID> <<= <NUMBER>` | equivalent to `<ID> = <ID> << <NUMBER>`, see [bit operations](/syntax/arith_expr.md#bit_operations) |
| `<ID> >>= <NUMBER>` | equivalent to `<ID> = <ID> >> <NUMBER>`, see [bit operations](/syntax/arith_expr#bit_operations) | | `<ID> >>= <NUMBER>` | equivalent to `<ID> = <ID> >> <NUMBER>`, see [bit operations](/syntax/arith_expr.md#bit_operations) |
| `<ID> &= <EXPR>` | equivalent to `<ID> = <ID> & <EXPR>`, see [bit operations](/syntax/arith_expr#bit_operations) | | `<ID> &= <EXPR>` | equivalent to `<ID> = <ID> & <EXPR>`, see [bit operations](/syntax/arith_expr.md#bit_operations) |
| `<ID> ^= <EXPR>` | equivalent to `<ID> = <ID> ^ <EXPR>`, see [bit operations](/syntax/arith_expr#bit_operations) | | `<ID> ^= <EXPR>` | equivalent to `<ID> = <ID> ^ <EXPR>`, see [bit operations](/syntax/arith_expr.md#bit_operations) |
| `<ID> |= <EXPR>` | equivalent to `<ID> = <ID> | <EXPR>`, see [bit operations](/syntax/arith_expr#bit_operations) | | `<ID> |= <EXPR>` | equivalent to `<ID> = <ID> | <EXPR>`, see [bit operations](/syntax/arith_expr.md#bit_operations) |
### Calculations ### Calculations
@ -368,7 +368,7 @@ under set -e. \</WRAP\>
## Arithmetic expressions in Bash ## Arithmetic expressions in Bash
- [The C-style for-loop](/syntax/ccmd/c_for) - [The C-style for-loop](/syntax/ccmd/c_for.md)
- [Arithmetic expansion](/syntax/expansion/arith) - [Arithmetic expansion](/syntax/expansion/arith.md)
- [Arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval) - [Arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval.md)
- [The "let" builtin command](/commands/builtin/let) - [The "let" builtin command](/commands/builtin/let.md)

View File

@ -30,7 +30,7 @@ Bash supports two different types of ksh-like one-dimensional arrays.
- *Indexed arrays* use positive integer numbers as keys. Indexed arrays - *Indexed arrays* use positive integer numbers as keys. Indexed arrays
are **always sparse**, meaning indexes are not necessarily contiguous. are **always sparse**, meaning indexes are not necessarily contiguous.
All syntax used for both assigning and dereferencing indexed arrays is All syntax used for both assigning and dereferencing indexed arrays is
an [arithmetic evaluation context](/syntax/arith_expr) (see an [arithmetic evaluation context](/syntax/arith_expr.md) (see
[\#Referencing](#Referencing)). As in C and many other languages, the [\#Referencing](#Referencing)). As in C and many other languages, the
numerical array indexes start at 0 (zero). Indexed arrays are the most numerical array indexes start at 0 (zero). Indexed arrays are the most
common, useful, and portable type. Indexed arrays were first common, useful, and portable type. Indexed arrays were first
@ -75,7 +75,7 @@ the closing bracket up to the end of the parameter name.
With few exceptions, names of this form may be used anywhere ordinary With few exceptions, names of this form may be used anywhere ordinary
parameter names are valid, such as within [arithmetic parameter names are valid, such as within [arithmetic
expressions](/syntax/arith_expr), [parameter expansions](/syntax/pe), expressions](/syntax/arith_expr.md), [parameter expansions](/syntax/pe.md),
and as arguments to builtins that accept parameter names. An *array* is and as arguments to builtins that accept parameter names. An *array* is
a Bash parameter that has been given the `-a` (for indexed) or `-A` (for a Bash parameter that has been given the `-a` (for indexed) or `-A` (for
associative) *attributes*. However, any regular (non-special or associative) *attributes*. However, any regular (non-special or
@ -116,7 +116,7 @@ variables.
| Syntax | Description | | Syntax | Description |
|:--------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |:--------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ARRAY[N]=VALUE` | Sets the element `N` of the **indexed** array `ARRAY` to `VALUE`. **`N` can be any valid [arithmetic expression](/syntax/arith_expr)**. | | `ARRAY[N]=VALUE` | Sets the element `N` of the **indexed** array `ARRAY` to `VALUE`. **`N` can be any valid [arithmetic expression](/syntax/arith_expr.md)**. |
| `ARRAY[STRING]=VALUE` | Sets the element indexed by `STRING` of the **associative array** `ARRAY`. | | `ARRAY[STRING]=VALUE` | Sets the element indexed by `STRING` of the **associative array** `ARRAY`. |
| `ARRAY=VALUE` | As above. If no index is given, as a default the zeroth element is set to `VALUE`. Careful, this is even true of associative arrays - there is no error if no key is specified, and the value is assigned to string index "0". | | `ARRAY=VALUE` | As above. If no index is given, as a default the zeroth element is set to `VALUE`. Careful, this is even true of associative arrays - there is no error if no key is specified, and the value is assigned to string index "0". |
| `ARRAY=(E1\ E2\ ...)` | Compound array assignment - sets the whole array `ARRAY` to the given list of elements indexed sequentially starting at zero. The array is unset before assignment unless the += operator is used. When the list is empty (`ARRAY=()`), the array will be set to an empty array. This method obviously does not use explicit indexes. An **associative array** can **not** be set like that! Clearing an associative array using `ARRAY=()` works. | | `ARRAY=(E1\ E2\ ...)` | Compound array assignment - sets the whole array `ARRAY` to the given list of elements indexed sequentially starting at zero. The array is unset before assignment unless the += operator is used. When the list is empty (`ARRAY=()`), the array will be set to an empty array. This method obviously does not use explicit indexes. An **associative array** can **not** be set like that! Clearing an associative array using `ARRAY=()` works. |
@ -130,7 +130,7 @@ As of now, arrays can't be exported.
### Getting values ### Getting values
| :shell: For completeness and details on several parameter expansion | :shell: For completeness and details on several parameter expansion
variants, see the [article about parameter expansion](/syntax/pe) and variants, see the [article about parameter expansion](/syntax/pe.md) and
check the notes about arrays. | check the notes about arrays. |
| --- | | --- |
@ -138,13 +138,13 @@ check the notes about arrays. |
|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `${ARRAY[N]}` | Expands to the value of the index `N` in the **indexed** array `ARRAY`. If `N` is a negative number, it's treated as the offset from the maximum assigned index (can't be used for assignment) - 1 | | `${ARRAY[N]}` | Expands to the value of the index `N` in the **indexed** array `ARRAY`. If `N` is a negative number, it's treated as the offset from the maximum assigned index (can't be used for assignment) - 1 |
| `${ARRAY[S]}` | Expands to the value of the index `S` in the **associative** array `ARRAY`. | | `${ARRAY[S]}` | Expands to the value of the index `S` in the **associative** array `ARRAY`. |
| `"${ARRAY[@]}" ${ARRAY[@]} "${ARRAY[*]}" ${ARRAY[*]}` | Similar to [mass-expanding positional parameters](/scripting/posparams#mass_usage), this expands to all elements. If unquoted, both subscripts `*` and `@` expand to the same result, if quoted, `@` expands to all elements individually quoted, `*` expands to all elements quoted as a whole. | | `"${ARRAY[@]}" ${ARRAY[@]} "${ARRAY[*]}" ${ARRAY[*]}` | Similar to [mass-expanding positional parameters](/scripting/posparams.md#mass_usage), this expands to all elements. If unquoted, both subscripts `*` and `@` expand to the same result, if quoted, `@` expands to all elements individually quoted, `*` expands to all elements quoted as a whole. |
| `"${ARRAY[@]:N:M}" ${ARRAY[@]:N:M} "${ARRAY[*]:N:M}" ${ARRAY[*]:N:M}` | Similar to what this syntax does for the characters of a single string when doing [substring expansion](/syntax/pe#substring_expansion), this expands to `M` elements starting with element `N`. This way you can mass-expand individual indexes. The rules for quoting and the subscripts `*` and `@` are the same as above for the other mass-expansions. | | `"${ARRAY[@]:N:M}" ${ARRAY[@]:N:M} "${ARRAY[*]:N:M}" ${ARRAY[*]:N:M}` | Similar to what this syntax does for the characters of a single string when doing [substring expansion](/syntax/pe.md#substring_expansion), this expands to `M` elements starting with element `N`. This way you can mass-expand individual indexes. The rules for quoting and the subscripts `*` and `@` are the same as above for the other mass-expansions. |
For clarification: When you use the subscripts `@` or `*` for For clarification: When you use the subscripts `@` or `*` for
mass-expanding, then the behaviour is exactly what it is for `$@` and mass-expanding, then the behaviour is exactly what it is for `$@` and
`$*` when [mass-expanding the positional `$*` when [mass-expanding the positional
parameters](/scripting/posparams#mass_usage). You should read this parameters](/scripting/posparams.md#mass_usage). You should read this
article to understand what's going on. article to understand what's going on.
### Metadata ### Metadata
@ -220,7 +220,7 @@ variables with unset.
| :warning: Specifying unquoted array elements as arguments to any | :warning: Specifying unquoted array elements as arguments to any
command, such as with the syntax above **may cause [pathname command, such as with the syntax above **may cause [pathname
expansion](/syntax/expansion/globs) to occur** due to the presence of expansion](/syntax/expansion/globs.md) to occur** due to the presence of
glob characters. glob characters.
Example: You are in a directory with a file named `x1`, and you want to Example: You are in a directory with a file named `x1`, and you want to
@ -710,10 +710,10 @@ to generate these results.
## See also ## See also
- [Parameter expansion](/syntax/pe) (contains sections for arrays) - [Parameter expansion](/syntax/pe.md) (contains sections for arrays)
- [classic_for](/syntax/ccmd/classic_for) (contains some examples to - [classic_for](/syntax/ccmd/classic_for.md) (contains some examples to
iterate over arrays) iterate over arrays)
- [declare](/commands/builtin/declare) - [declare](/commands/builtin/declare.md)
- [BashFAQ 005 - How can I use array - [BashFAQ 005 - How can I use array
variables?](http://mywiki.wooledge.org/BashFAQ/005) - A very detailed variables?](http://mywiki.wooledge.org/BashFAQ/005) - A very detailed
discussion on arrays with many examples. discussion on arrays with many examples.

View File

@ -42,7 +42,7 @@ issue to report back to the calling program.
**base** for all higher constructs. Everything you execute, from **base** for all higher constructs. Everything you execute, from
pipelines to functions, finally ends up in (many) simple commands. pipelines to functions, finally ends up in (many) simple commands.
That's why Bash only has one method to [expand and execute a simple That's why Bash only has one method to [expand and execute a simple
command](/syntax/grammar/parser_exec). \</wrap\> command](/syntax/grammar/parser_exec.md). \</wrap\>
## Pipelines ## Pipelines
@ -81,7 +81,7 @@ the leading `!` will "invert" the exit code, and the shell sees (and
acts on) exit code 0 (TRUE) and the `then` part of the `if` stanza is acts on) exit code 0 (TRUE) and the `then` part of the `if` stanza is
executed. One could say we checked for "`not grep "^root" /etc/passwd`". executed. One could say we checked for "`not grep "^root" /etc/passwd`".
The [set option pipefail](/commands/builtin/set#attributes) determines The [set option pipefail](/commands/builtin/set.md#attributes) determines
the behavior of how bash reports the exit code of a pipeline. If it's the behavior of how bash reports the exit code of a pipeline. If it's
set, then the exit code (`$?`) is the last command that exits with non set, then the exit code (`$?`) is the last command that exits with non
zero status, if none fail, it's zero. If it's not set, then `$?` always zero status, if none fail, it's zero. If it's not set, then `$?` always
@ -131,7 +131,7 @@ Your whole Bash script technically is one big single list!
## Compound Commands ## Compound Commands
See also the [list of compound commands](/syntax/ccmd/intro). See also the [list of compound commands](/syntax/ccmd/intro.md).
There are two forms of compound commands: There are two forms of compound commands:
@ -150,17 +150,17 @@ overview):
| Compound command syntax | Description | | Compound command syntax | Description |
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------| |------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `( <LIST> )` | Execute `<LIST>` in an extra subshell =\> [article](/syntax/ccmd/grouping_subshell) | | `( <LIST> )` | Execute `<LIST>` in an extra subshell =\> [article](/syntax/ccmd/grouping_subshell.md) |
| `{ <LIST> ; }` | Execute `<LIST>` as separate group (but not in a subshell) =\> [article](/syntax/ccmd/grouping_plain) | | `{ <LIST> ; }` | Execute `<LIST>` as separate group (but not in a subshell) =\> [article](/syntax/ccmd/grouping_plain.md) |
| `(( <EXPRESSION> ))` | Evaluate the arithmetic expression `<EXPRESSION>` =\> [article](/syntax/ccmd/arithmetic_eval) | | `(( <EXPRESSION> ))` | Evaluate the arithmetic expression `<EXPRESSION>` =\> [article](/syntax/ccmd/arithmetic_eval.md) |
| `[[ <EXPRESSION> ]]` | Evaluate the conditional expression `<EXPRESSION>` (aka "the new test command") =\> [article](/syntax/ccmd/conditional_expression) | | `[[ <EXPRESSION> ]]` | Evaluate the conditional expression `<EXPRESSION>` (aka "the new test command") =\> [article](/syntax/ccmd/conditional_expression.md) |
| `for <NAME> in <WORDS> ; do <LIST> ; done` | Executes `<LIST>` while setting the variable `<NAME>` to one of `<WORDS>` on every iteration (classic for-loop) =\> [article](/syntax/ccmd/classic_for) | | `for <NAME> in <WORDS> ; do <LIST> ; done` | Executes `<LIST>` while setting the variable `<NAME>` to one of `<WORDS>` on every iteration (classic for-loop) =\> [article](/syntax/ccmd/classic_for.md) |
| `for (( <EXPR1> ; <EXPR2> ; <EXPR3> )) ; do <LIST> ; done` | C-style for-loop (driven by arithmetic expressions) =\> [article](/syntax/ccmd/c_for) | | `for (( <EXPR1> ; <EXPR2> ; <EXPR3> )) ; do <LIST> ; done` | C-style for-loop (driven by arithmetic expressions) =\> [article](/syntax/ccmd/c_for.md) |
| `select <NAME> in <WORDS> ; do <LIST> ; done` | Provides simple menus =\> [article](/syntax/ccmd/user_select) | | `select <NAME> in <WORDS> ; do <LIST> ; done` | Provides simple menus =\> [article](/syntax/ccmd/user_select.md) |
| `case <WORD> in <PATTERN>) <LIST> ;; ... esac` | Decisions based on pattern matching - executing `<LIST>` on match =\> [article](/syntax/ccmd/case) | | `case <WORD> in <PATTERN>) <LIST> ;; ... esac` | Decisions based on pattern matching - executing `<LIST>` on match =\> [article](/syntax/ccmd/case.md) |
| `if <LIST> ; then <LIST> ; else <LIST> ; fi` | The if clause: makes decisions based on exit codes =\> [article](/syntax/ccmd/if_clause) | | `if <LIST> ; then <LIST> ; else <LIST> ; fi` | The if clause: makes decisions based on exit codes =\> [article](/syntax/ccmd/if_clause.md) |
| `while <LIST1> ; do <LIST2> ; done` | Execute `<LIST2>` while `<LIST1>` returns TRUE (exit code) =\> [article](/syntax/ccmd/while_loop) | | `while <LIST1> ; do <LIST2> ; done` | Execute `<LIST2>` while `<LIST1>` returns TRUE (exit code) =\> [article](/syntax/ccmd/while_loop.md) |
| `until <LIST1> ; do <LIST2> ; done` | Execute `<LIST2>` until `<LIST1>` returns TRUE (exit code) =\> [article](/syntax/ccmd/until_loop) | | `until <LIST1> ; do <LIST2> ; done` | Execute `<LIST2>` until `<LIST1>` returns TRUE (exit code) =\> [article](/syntax/ccmd/until_loop.md) |
## Shell Function Definitions ## Shell Function Definitions
@ -320,10 +320,10 @@ Let's invert test command exit code, only one thing changes:
## See also ## See also
- Internal: [List of compound commands](/syntax/ccmd/intro) - Internal: [List of compound commands](/syntax/ccmd/intro.md)
- Internal: [Parsing and execution of simple - Internal: [Parsing and execution of simple
commands](/syntax/grammar/parser_exec) commands](/syntax/grammar/parser_exec.md)
- Internal: [Quoting and escaping](/syntax/quoting) - Internal: [Quoting and escaping](/syntax/quoting.md)
- Internal: [Introduction to expansions and - Internal: [Introduction to expansions and
substitutions](/syntax/expansion/intro) substitutions](/syntax/expansion/intro.md)
- Internal: [Some words about words...](/syntax/words) - Internal: [Some words about words...](/syntax/words.md)

View File

@ -6,17 +6,17 @@
## Description ## Description
This command evaluates the [arithmetic expression](/syntax/arith_expr) This command evaluates the [arithmetic expression](/syntax/arith_expr.md)
`<EXPRESSION>`. `<EXPRESSION>`.
If the expression evaluates to 0 then the exit code of the expression is If the expression evaluates to 0 then the exit code of the expression is
set to 1 (`FALSE`). If the expression evaluates to something else than set to 1 (`FALSE`). If the expression evaluates to something else than
0, then the exit code of the expression is set to 0 (`TRUE`). For this 0, then the exit code of the expression is set to 0 (`TRUE`). For this
return code mapping, please see [this return code mapping, please see [this
section](/syntax/arith_expr#arithmetic_expressions_and_return_codes). section](/syntax/arith_expr.md#arithmetic_expressions_and_return_codes).
The functionality basically is equivalent to what the [`let` builtin The functionality basically is equivalent to what the [`let` builtin
command](/commands/builtin/let) does. The arithmetic evaluation compound command](/commands/builtin/let.md) does. The arithmetic evaluation compound
command should be preferred. command should be preferred.
## Examples ## Examples
@ -25,6 +25,6 @@ command should be preferred.
## See also ## See also
- Internal: [arithmetic expressions](/syntax/arith_expr) - Internal: [arithmetic expressions](/syntax/arith_expr.md)
- Internal: [arithmetic expansion](/syntax/expansion/arith) - Internal: [arithmetic expansion](/syntax/expansion/arith.md)
- Internal: [The `let` builtin command](/commands/builtin/let) - Internal: [The `let` builtin command](/commands/builtin/let.md)

View File

@ -29,7 +29,7 @@ mechanisms available in the language.
The `((;;))` syntax at the top of the loop is not an ordinary The `((;;))` syntax at the top of the loop is not an ordinary
[arithmetic compound command](syntax/ccmd/arithmetic_eval), but is part [arithmetic compound command](syntax/ccmd/arithmetic_eval), but is part
of the C-style for-loop's own syntax. The three sections separated by of the C-style for-loop's own syntax. The three sections separated by
semicolons are [arithmetic expression](/syntax/arith_expr) contexts. semicolons are [arithmetic expression](/syntax/arith_expr.md) contexts.
Each time one of the sections is to be evaluated, the section is first Each time one of the sections is to be evaluated, the section is first
processed for: brace, parameter, command, arithmetic, and process processed for: brace, parameter, command, arithmetic, and process
substitution/expansion as usual for arithmetic contexts. When the loop substitution/expansion as usual for arithmetic contexts. When the loop
@ -60,7 +60,7 @@ loop can be:
The equivalent construct using a [while loop](syntax/ccmd/while_loop) The equivalent construct using a [while loop](syntax/ccmd/while_loop)
and the [arithmetic expression compound and the [arithmetic expression compound
command](/syntax/ccmd/arithmetic_eval) would be structured as: command](/syntax/ccmd/arithmetic_eval.md) would be structured as:
(( <EXPR1> )) (( <EXPR1> ))
while (( <EXPR2> )); do while (( <EXPR2> )); do
@ -135,7 +135,7 @@ ending at 1. If that bit is set in the `testbyte`, it prints "`1`", else
bits). bits).
#!/usr/bin/env bash #!/usr/bin/env bash
# Example written for http://wiki.bash-hackers.org/syntax/ccmd/c_for#bits_analyzer # Example written for http://wiki.bash-hackers.org/syntax/ccmd/c_for.md#bits_analyzer
# Based on TheBonsai's original. # Based on TheBonsai's original.
function toBin { function toBin {
@ -231,6 +231,6 @@ variables.
## See also ## See also
- Internal: [Arithmetic expressions](/syntax/arith_expr) - Internal: [Arithmetic expressions](/syntax/arith_expr.md)
- Internal: [The classic for-loop](/syntax/ccmd/classic_for) - Internal: [The classic for-loop](/syntax/ccmd/classic_for.md)
- Internal: [The while-loop](/syntax/ccmd/while_loop) - Internal: [The while-loop](/syntax/ccmd/while_loop.md)

View File

@ -13,9 +13,9 @@
## Description ## Description
The `case`-statement can execute commands based on a [pattern The `case`-statement can execute commands based on a [pattern
matching](/syntax/pattern) decision. The word `<WORD>` is matched matching](/syntax/pattern.md) decision. The word `<WORD>` is matched
against every pattern `<PATTERNn>` and on a match, the associated against every pattern `<PATTERNn>` and on a match, the associated
[list](/syntax/basicgrammar#lists) `<LISTn>` is executed. Every [list](/syntax/basicgrammar.md#lists) `<LISTn>` is executed. Every
commandlist is terminated by `;;`. This rule is optional for the very commandlist is terminated by `;;`. This rule is optional for the very
last commandlist (i.e., you can omit the `;;` before the `esac`). Every last commandlist (i.e., you can omit the `;;` before the `esac`). Every
`<PATTERNn>` is separated from it's associated `<LISTn>` by a `)`, and `<PATTERNn>` is separated from it's associated `<LISTn>` by a `)`, and
@ -43,7 +43,7 @@ done**, which means you can leave expansions unquoted without problems:
esac esac
This is similar to the behavior of the [conditional expression command This is similar to the behavior of the [conditional expression command
("new test command")](/syntax/ccmd/conditional_expression) (also no word ("new test command")](/syntax/ccmd/conditional_expression.md) (also no word
splitting for expansions). splitting for expansions).
Unlike the C-case-statement, only the matching list and nothing else is Unlike the C-case-statement, only the matching list and nothing else is

View File

@ -66,7 +66,7 @@ empty"!).
### Iterate over array elements ### Iterate over array elements
With some array syntax (see [arrays](/syntax/arrays)) you can easily With some array syntax (see [arrays](/syntax/arrays.md)) you can easily
"feed" the for-loop to iterate over all elements in an array (by "feed" the for-loop to iterate over all elements in an array (by
mass-expanding all elements): mass-expanding all elements):
@ -88,7 +88,7 @@ done
### List positional parameters ### List positional parameters
You can use this You can use this
[function](/syntax/basicgrammar#shell_function_definitions) to test how [function](/syntax/basicgrammar.md#shell_function_definitions) to test how
arguments to a command will be interpreted and parsed, and finally used: arguments to a command will be interpreted and parsed, and finally used:
``` bash ``` bash
@ -138,7 +138,7 @@ done
This is just an example. In *general* This is just an example. In *general*
- it's not a good idea to parse `ls(1)` output - it's not a good idea to parse `ls(1)` output
- the [while loop](/syntax/ccmd/while_loop) (using the `read` command) - the [while loop](/syntax/ccmd/while_loop.md) (using the `read` command)
is a better joice to iterate over lines is a better joice to iterate over lines
### Nested for-loops ### Nested for-loops
@ -157,7 +157,7 @@ done
### Loop over a number range ### Loop over a number range
Beginning in Bash 4, you can also use "sequence expression" form of Beginning in Bash 4, you can also use "sequence expression" form of
[brace expansion](/syntax/expansion/brace) syntax when looping over [brace expansion](/syntax/expansion/brace.md) syntax when looping over
numbers, and this form does not create leading zeroes unless you ask for numbers, and this form does not create leading zeroes unless you ask for
them: them:

View File

@ -10,14 +10,14 @@
## Description ## Description
The [list](/syntax/basicgrammar#lists) `<LIST>` is simply executed in The [list](/syntax/basicgrammar.md#lists) `<LIST>` is simply executed in
the **current** shell environment. The list must be terminated with a the **current** shell environment. The list must be terminated with a
**newline** or **semicolon**. For parsing reasons, the curly braces must **newline** or **semicolon**. For parsing reasons, the curly braces must
be separated from `<LIST>` by a **semicolon** and **blanks** if they're be separated from `<LIST>` by a **semicolon** and **blanks** if they're
in the same line! [^1][^2] in the same line! [^1][^2]
This is known as a **group command**. The return status is the [exit This is known as a **group command**. The return status is the [exit
status (exit code)](/scripting/basics#exit_codes) of the list. status (exit code)](/scripting/basics.md#exit_codes) of the list.
The input and output **filedescriptors** are cumulative: The input and output **filedescriptors** are cumulative:
@ -30,7 +30,7 @@ The input and output **filedescriptors** are cumulative:
} >output.txt } >output.txt
This compound command also usually is the body of a [function This compound command also usually is the body of a [function
definition](/syntax/basicgrammar#shell_function_definitions), though not definition](/syntax/basicgrammar.md#shell_function_definitions), though not
the only compound command that's valid there: the only compound command that's valid there:
print_help() { print_help() {

View File

@ -6,7 +6,7 @@
## Description ## Description
The [list](/syntax/basicgrammar#lists) `<LIST>` is executed in a The [list](/syntax/basicgrammar.md#lists) `<LIST>` is executed in a
separate shell - a subprocess. No changes to the environment (variables separate shell - a subprocess. No changes to the environment (variables
etc...) are reflected in the "main shell". etc...) are reflected in the "main shell".
@ -31,5 +31,5 @@ echo "$PWD" # Still in the original directory.
## See also ## See also
- [grouping commands](/syntax/ccmd/grouping_plain) - [grouping commands](/syntax/ccmd/grouping_plain.md)
- [Subshells on Greycat's wiki](http://mywiki.wooledge.org/SubShell) - [Subshells on Greycat's wiki](http://mywiki.wooledge.org/SubShell)

View File

@ -26,10 +26,10 @@ The `if`-clause can control the script's flow (what's executed) by
looking at the exit codes of other commands. looking at the exit codes of other commands.
All commandsets `<LIST>` are interpreted as [command All commandsets `<LIST>` are interpreted as [command
lists](/syntax/basicgrammar#lists), thus they can contain the whole lists](/syntax/basicgrammar.md#lists), thus they can contain the whole
palette from [simple commands](/syntax/basicgrammar#simple_commands) palette from [simple commands](/syntax/basicgrammar.md#simple_commands)
over [pipelines](/syntax/basicgrammar#pipelines) to [compound over [pipelines](/syntax/basicgrammar.md#pipelines) to [compound
commands](/syntax/basicgrammar#compound_commands) (and their commands](/syntax/basicgrammar.md#compound_commands) (and their
combination) as condition. combination) as condition.
### Operation ### Operation
@ -88,4 +88,4 @@ example above (multiple commands):
## See also ## See also
- Internal: [the classic test command](/commands/classictest) - Internal: [the classic test command](/commands/classictest.md)

View File

@ -2,8 +2,8 @@
The main part of Bash's syntax are the so-called **compound commands**. The main part of Bash's syntax are the so-called **compound commands**.
They're called like that because they use "real" commands ([simple They're called like that because they use "real" commands ([simple
commands](/syntax/basicgrammar#simple_commands) or commands](/syntax/basicgrammar.md#simple_commands) or
[lists](/syntax/basicgrammar#lists)) and knit some intelligence around [lists](/syntax/basicgrammar.md#lists)) and knit some intelligence around
them. That is what the essential "Bash language" is made of. them. That is what the essential "Bash language" is made of.
## Command grouping ## Command grouping
@ -14,7 +14,7 @@ them. That is what the essential "Bash language" is made of.
## Conditional reactions ## Conditional reactions
Note that conditionals can also be scripted using Note that conditionals can also be scripted using
[list](/syntax/basicgrammar#lists), which are syntax elements, not [list](/syntax/basicgrammar.md#lists), which are syntax elements, not
commands. commands.
- the "new" test command: [conditional - the "new" test command: [conditional

View File

@ -9,12 +9,12 @@
## Description ## Description
The until-loop is relatively simple in what it does: it executes the The until-loop is relatively simple in what it does: it executes the
[command list](/syntax/basicgrammar#lists) `<LIST1>` and if the exit [command list](/syntax/basicgrammar.md#lists) `<LIST1>` and if the exit
code of it was **not** 0 (FALSE) it executes `<LIST2>`. This happens code of it was **not** 0 (FALSE) it executes `<LIST2>`. This happens
again and again until `<LIST1>` returns TRUE. again and again until `<LIST1>` returns TRUE.
This is exactly the opposite of the [while This is exactly the opposite of the [while
loop](/syntax/ccmd/while_loop). loop](/syntax/ccmd/while_loop.md).
:!: Like all loops (both `for`-loops, `while` and `until`), this loop :!: Like all loops (both `for`-loops, `while` and `until`), this loop
can be can be
@ -35,4 +35,4 @@ or `0` (`TRUE`) if none was executed.
## See also ## See also
- Internal: [The while loop](/syntax/ccmd/while_loop) - Internal: [The while loop](/syntax/ccmd/while_loop.md)

View File

@ -27,7 +27,7 @@
This compound command provides a kind of menu. The user is prompted with This compound command provides a kind of menu. The user is prompted with
a *numbered list* of the given words, and is asked to input the index a *numbered list* of the given words, and is asked to input the index
number of the word. If a word was selected, the variable `<NAME>` is set number of the word. If a word was selected, the variable `<NAME>` is set
to this word, and the [list](/syntax/basicgrammar#lists) `<LIST>` is to this word, and the [list](/syntax/basicgrammar.md#lists) `<LIST>` is
executed. executed.
If no `in <WORDS>` is given, then the positional parameters are taken as If no `in <WORDS>` is given, then the positional parameters are taken as

View File

@ -9,12 +9,12 @@
## Description ## Description
The while-loop is relatively simple in what it does: it executes the The while-loop is relatively simple in what it does: it executes the
[command list](/syntax/basicgrammar#lists) `<LIST1>` and if the exit [command list](/syntax/basicgrammar.md#lists) `<LIST1>` and if the exit
code of it was 0 (TRUE) it executes `<LIST2>`. This happens again and code of it was 0 (TRUE) it executes `<LIST2>`. This happens again and
again until `<LIST1>` returns FALSE. again until `<LIST1>` returns FALSE.
This is exactly the opposite of the [until This is exactly the opposite of the [until
loop](/syntax/ccmd/until_loop). loop](/syntax/ccmd/until_loop.md).
:!: Like all loops (both `for`-loops, `while` and `until`), this loop :!: Like all loops (both `for`-loops, `while` and `until`), this loop
can be can be
@ -35,7 +35,7 @@ or `0` (`TRUE`) if none was executed.
## See also ## See also
- Internal: [The until loop](/syntax/ccmd/until_loop) - Internal: [The until loop](/syntax/ccmd/until_loop.md)
- Internal: [code examples of the read builtin - Internal: [code examples of the read builtin
command](/commands/builtin/read#code_examples) to see how you can loop command](/commands/builtin/read.md#code_examples) to see how you can loop
over lines over lines

View File

@ -4,7 +4,7 @@
$[ <EXPRESSION> ] $[ <EXPRESSION> ]
The [arithmetic expression](/syntax/arith_expr) `<EXPRESSION>` is The [arithmetic expression](/syntax/arith_expr.md) `<EXPRESSION>` is
evaluated and expands to the result. The output of the arithmetic evaluated and expands to the result. The output of the arithmetic
expansion is guaranteed to be one word and a digit in Bash. expansion is guaranteed to be one word and a digit in Bash.
@ -29,7 +29,7 @@ function printSum {
**Note** that in Bash you don't need the arithmetic expansion to check **Note** that in Bash you don't need the arithmetic expansion to check
for the boolean value of an arithmetic expression. This can be done for the boolean value of an arithmetic expression. This can be done
using the [arithmetic evaluation compound using the [arithmetic evaluation compound
command](/syntax/ccmd/arithmetic_eval): command](/syntax/ccmd/arithmetic_eval.md):
``` bash ``` bash
printf %s 'Enter a number: ' >&2 printf %s 'Enter a number: ' >&2
@ -66,8 +66,8 @@ echo $(($x[0])) # Error. This expands to $((1[0])), an invalid expression.
## See also ## See also
- [arithmetic expressions](/syntax/arith_expr) - [arithmetic expressions](/syntax/arith_expr.md)
- [arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval) - [arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval.md)
- [Introduction to expansion and substitution](/syntax/expansion/intro) - [Introduction to expansion and substitution](/syntax/expansion/intro.md)
- [POSIX - [POSIX
definition](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04) definition](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04)

View File

@ -40,7 +40,7 @@ embedded inside a for loop : `for i in $(eval echo {$a..$b})` This
requires that the entire command be properly escaped to avoid unexpected requires that the entire command be properly escaped to avoid unexpected
expansions. If the sequence expansion is to be assigned to an array, expansions. If the sequence expansion is to be assigned to an array,
another method is possible using [declaration another method is possible using [declaration
commands](/commands/builtin/declare): commands](/commands/builtin/declare.md):
`declare -a 'pics=(img{'"$a..$b"'}.png)'; mv "${pics[@]}" ../imgs` `declare -a 'pics=(img{'"$a..$b"'}.png)'; mv "${pics[@]}" ../imgs`
This is significantly safer, but one must still be careful to control This is significantly safer, but one must still be careful to control
the values of \$a and \$b. Both the exact quoting, and explicitly the values of \$a and \$b. Both the exact quoting, and explicitly

View File

@ -14,8 +14,8 @@ All **trailing** newlines are removed (below is an example for a
workaround). workaround).
In later steps, **if not quoted**, the results undergo [word In later steps, **if not quoted**, the results undergo [word
splitting](/syntax/expansion/wordsplit) and [pathname splitting](/syntax/expansion/wordsplit.md) and [pathname
expansion](/syntax/expansion/globs). You have to remember that, because expansion](/syntax/expansion/globs.md). You have to remember that, because
the word splitting will also remove embedded newlines and other `IFS` the word splitting will also remove embedded newlines and other `IFS`
characters and break the results up into several words. Also you'll characters and break the results up into several words. Also you'll
probably get unexpected pathname matches. **If you need the literal probably get unexpected pathname matches. **If you need the literal
@ -25,14 +25,14 @@ The second form `` `COMMAND` `` is more or less obsolete for Bash, since
it has some trouble with nesting ("inner" backticks need to be escaped) it has some trouble with nesting ("inner" backticks need to be escaped)
and escaping characters. Use `$(COMMAND)`, it's also POSIX! and escaping characters. Use `$(COMMAND)`, it's also POSIX!
When you [call an explicit subshell](/syntax/ccmd/grouping_subshell) When you [call an explicit subshell](/syntax/ccmd/grouping_subshell.md)
`(COMMAND)` inside the command substitution `$()`, then take care, this `(COMMAND)` inside the command substitution `$()`, then take care, this
way is **wrong**: way is **wrong**:
$((COMMAND)) $((COMMAND))
Why? because it collides with the syntax for [arithmetic Why? because it collides with the syntax for [arithmetic
expansion](/syntax/expansion/arith). You need to separate the command expansion](/syntax/expansion/arith.md). You need to separate the command
substitution from the inner `(COMMAND)`: substitution from the inner `(COMMAND)`:
$( (COMMAND) ) $( (COMMAND) )
@ -133,5 +133,5 @@ output with its trailing newlines.
## See also ## See also
- Internal: [Introduction to expansion and - Internal: [Introduction to expansion and
substitution](/syntax/expansion/intro) substitution](/syntax/expansion/intro.md)
- Internal: [Obsolete and deprecated syntax](/scripting/obsolete) - Internal: [Obsolete and deprecated syntax](/scripting/obsolete.md)

View File

@ -11,16 +11,16 @@ expanded filenames as its arguments (here, all filenames matching
grep "changes:" *.log grep "changes:" *.log
The base syntax for the pathname expansion is the [pattern The base syntax for the pathname expansion is the [pattern
matching](/syntax/pattern) syntax. The pattern you describe is matched matching](/syntax/pattern.md) syntax. The pattern you describe is matched
against all existing filenames and the matching ones are substituted. against all existing filenames and the matching ones are substituted.
Since this substitution happens **after [word Since this substitution happens **after [word
splitting](/syntax/expansion/wordsplit)**, all resulting filenames are splitting](/syntax/expansion/wordsplit.md)**, all resulting filenames are
literal and treated as separate words, no matter how many spaces or literal and treated as separate words, no matter how many spaces or
other `IFS`-characters they contain. other `IFS`-characters they contain.
## Normal behaviour ## Normal behaviour
- with [the set command](/commands/builtin/set) (`-f`, `noglob`) you can - with [the set command](/commands/builtin/set.md) (`-f`, `noglob`) you can
entirely disable pathname expansion entirely disable pathname expansion
- when matching a pathname, the slash-character (`/`) always needs to be - when matching a pathname, the slash-character (`/`) always needs to be
matched explicitly matched explicitly
@ -49,7 +49,7 @@ other `IFS`-characters they contain.
globs (e.g. `[A-Z]`) use C locale order rather than the configured globs (e.g. `[A-Z]`) use C locale order rather than the configured
locale's order (i.e. `ABC...abc...` instead of e.g. `AaBbCc...`) - locale's order (i.e. `ABC...abc...` instead of e.g. `AaBbCc...`) -
since 4.3-alpha since 4.3-alpha
- the variable [GLOBIGNORE](/syntax/shellvars#GLOBIGNORE) can be set to - the variable [GLOBIGNORE](/syntax/shellvars.md#GLOBIGNORE) can be set to
a colon-separated list of patterns to be removed from the list before a colon-separated list of patterns to be removed from the list before
it is returned it is returned
@ -66,7 +66,7 @@ In this example, no files matched the pattern, so the glob was left
intact (a literal asterisk, followed by dot-txt). intact (a literal asterisk, followed by dot-txt).
This can be very annoying, for example when you drive a This can be very annoying, for example when you drive a
[for-loop](/syntax/ccmd/classic_for) using the pathname expansion: [for-loop](/syntax/ccmd/classic_for.md) using the pathname expansion:
for filename in *.txt; do for filename in *.txt; do
echo "=== BEGIN: $filename ===" echo "=== BEGIN: $filename ==="
@ -106,8 +106,8 @@ followed by two numbers, followed by at least 3 more characters:
## See also ## See also
- [Introduction to expansion and substitution](/syntax/expansion/intro) - [Introduction to expansion and substitution](/syntax/expansion/intro.md)
- [pattern matching syntax](/syntax/pattern) - [pattern matching syntax](/syntax/pattern.md)
- [the set builtin command](/commands/builtin/set) - [the set builtin command](/commands/builtin/set.md)
- [the shopt builtin command](/commands/builtin/shopt) - [the shopt builtin command](/commands/builtin/shopt.md)
- [list of shell options](/internals/shell_options) - [list of shell options](/internals/shell_options.md)

View File

@ -21,7 +21,7 @@ string "`$mystring`" to "`Hello world`", so that `echo` will only see
After all these expansions and substitutions are done, all quotes that After all these expansions and substitutions are done, all quotes that
are not meant literally (i.e., [the quotes that marked contiguous are not meant literally (i.e., [the quotes that marked contiguous
words](/syntax/quoting), as part of the shell syntax) are removed from words](/syntax/quoting.md), as part of the shell syntax) are removed from
the commandline text, so the called program won't see them. This step is the commandline text, so the called program won't see them. This step is
called **quote-removal**. called **quote-removal**.
@ -30,28 +30,28 @@ called **quote-removal**.
Saw a possible expansion syntax but don't know what it is? Here's a Saw a possible expansion syntax but don't know what it is? Here's a
small list. small list.
- [Parameter expansion](/syntax/pe) (it has its own [overview - [Parameter expansion](/syntax/pe.md) (it has its own [overview
section](/syntax/pe#overview)) section](/syntax/pe.md#overview))
- `$WORD` - `$WORD`
- `${STUFF...}` - `${STUFF...}`
- [Pathname expansion](/syntax/expansion/globs) - [Pathname expansion](/syntax/expansion/globs.md)
- `*.txt` - `*.txt`
- `page_1?.html` - `page_1?.html`
- [Arithmetic expansion](/syntax/expansion/arith) - [Arithmetic expansion](/syntax/expansion/arith.md)
- `$(( EXPRESSION ))` - `$(( EXPRESSION ))`
- `$[ EXPRESSION ]` - `$[ EXPRESSION ]`
- [Command substitution](/syntax/expansion/cmdsubst) - [Command substitution](/syntax/expansion/cmdsubst.md)
- `$( COMMAND )` - `$( COMMAND )`
- `` ` COMMAND ` `` - `` ` COMMAND ` ``
- [Tilde expansion](/syntax/expansion/tilde) - [Tilde expansion](/syntax/expansion/tilde.md)
- `~` - `~`
- `~+` - `~+`
- `~-` - `~-`
- [Brace expansion](/syntax/expansion/brace) - [Brace expansion](/syntax/expansion/brace.md)
- `{X,Y,Z}` - `{X,Y,Z}`
- `{X..Y}` - `{X..Y}`
- `{X..Y..Z}` - `{X..Y..Z}`
- [Process substitution](/syntax/expansion/proc_subst) - [Process substitution](/syntax/expansion/proc_subst.md)
- `<( COMMAND )` - `<( COMMAND )`
- `>( COMMAND )` - `>( COMMAND )`
@ -64,25 +64,25 @@ splitting!).
The order is (from first to last): The order is (from first to last):
- [Brace expansion](/syntax/expansion/brace) - [Brace expansion](/syntax/expansion/brace.md)
- [Tilde expansion](/syntax/expansion/tilde) - [Tilde expansion](/syntax/expansion/tilde.md)
- The following expansions happen at the same time, in a left-to-right - The following expansions happen at the same time, in a left-to-right
fashion on the commandline (see below) fashion on the commandline (see below)
- [Parameter expansion](/syntax/pe) - [Parameter expansion](/syntax/pe.md)
- [Arithmetic expansion](/syntax/expansion/arith) - [Arithmetic expansion](/syntax/expansion/arith.md)
- [Command substitution](/syntax/expansion/cmdsubst) - [Command substitution](/syntax/expansion/cmdsubst.md)
- [Word splitting](/syntax/expansion/wordsplit) - [Word splitting](/syntax/expansion/wordsplit.md)
- [Pathname expansion](/syntax/expansion/globs) - [Pathname expansion](/syntax/expansion/globs.md)
[Process substitution](/syntax/expansion/proc_subst) is performed [Process substitution](/syntax/expansion/proc_subst.md) is performed
**simultaneously** with [parameter expansion](/syntax/pe), [command **simultaneously** with [parameter expansion](/syntax/pe.md), [command
substitution](/syntax/expansion/cmdsubst) and [arithmetic substitution](/syntax/expansion/cmdsubst.md) and [arithmetic
expansion](/syntax/expansion/arith). It is only performed when the expansion](/syntax/expansion/arith.md). It is only performed when the
underlying operating system supports it. underlying operating system supports it.
The 3 steps [parameter expansion](/syntax/pe), [arithmetic The 3 steps [parameter expansion](/syntax/pe.md), [arithmetic
expansion](/syntax/expansion/arith) and [command expansion](/syntax/expansion/arith.md) and [command
substitution](/syntax/expansion/cmdsubst) happen at the same time in a substitution](/syntax/expansion/cmdsubst.md) happen at the same time in a
left-to-right fashion on nthe commandline. This means left-to-right fashion on nthe commandline. This means
i=1 i=1

View File

@ -10,11 +10,11 @@ of a process (some sequence of commands) appear as a temporary file.
>( <LIST> ) >( <LIST> )
Process substitution is performed **simultaneously** with [parameter Process substitution is performed **simultaneously** with [parameter
expansion](/syntax/pe), [command expansion](/syntax/pe.md), [command
substitution](/syntax/expansion/cmdsubst) and [arithmetic substitution](/syntax/expansion/cmdsubst.md) and [arithmetic
expansion](/syntax/expansion/arith). expansion](/syntax/expansion/arith.md).
The [command list](/syntax/basicgrammar#lists) `<LIST>` is executed and The [command list](/syntax/basicgrammar.md#lists) `<LIST>` is executed and
its its
- standard output filedescriptor in the `<( ... )` form or - standard output filedescriptor in the `<( ... )` form or
@ -127,7 +127,7 @@ echo "$counter files"
This is the normal input file redirection `< FILE`, just that the `FILE` This is the normal input file redirection `< FILE`, just that the `FILE`
in this case is the result of process substitution. It's important to in this case is the result of process substitution. It's important to
note that the space is required in order to disambiguate the syntax from note that the space is required in order to disambiguate the syntax from
[here documents](/syntax/redirection#here_documents). [here documents](/syntax/redirection.md#here_documents).
``` bash ``` bash
: < <(COMMAND) # Good. : < <(COMMAND) # Good.
@ -179,7 +179,7 @@ ${dev[${dev='dev[1>(${dev[dev]})]'}]}
## See also ## See also
- Internal: [Introduction to expansion and - Internal: [Introduction to expansion and
substitution](/syntax/expansion/intro) substitution](/syntax/expansion/intro.md)
- Internal: [Bash in the process tree](/scripting/processtree) - Internal: [Bash in the process tree](/scripting/processtree.md)
(subshells) (subshells)
- Internal: [Redirection](/syntax/redirection) - Internal: [Redirection](/syntax/redirection.md)

View File

@ -43,7 +43,7 @@ I don't know yet, if this is a bug or intended. |
| --- | | --- |
This way you can correctly use the tilde expansion in your This way you can correctly use the tilde expansion in your
[PATH](/syntax/shellvars#PATH): [PATH](/syntax/shellvars.md#PATH):
PATH=~/mybins:~peter/mybins:$PATH PATH=~/mybins:~peter/mybins:$PATH
@ -69,7 +69,7 @@ operating system for the associated home directory for `<NAME>`.
To find the home directory of the current user (`~`), Bash has a To find the home directory of the current user (`~`), Bash has a
precedence: precedence:
- expand to the value of [HOME](/syntax/shellvars#HOME) if it's defined - expand to the value of [HOME](/syntax/shellvars.md#HOME) if it's defined
- expand to the home directory of the user executing the shell - expand to the home directory of the user executing the shell
(operating system) (operating system)
@ -80,7 +80,7 @@ at least regarding tilde expansion.
~+ ~+
This expands to the value of the [PWD](/syntax/shellvars#PWD) variable, This expands to the value of the [PWD](/syntax/shellvars.md#PWD) variable,
which holds the currect working directory: which holds the currect working directory:
echo "CWD is $PWD" echo "CWD is $PWD"
@ -93,7 +93,7 @@ is equivalent to (note it **must** be a separate word!):
~- ~-
This expands to the value of the [OLDPWD](/syntax/shellvars#OLDPWD) This expands to the value of the [OLDPWD](/syntax/shellvars.md#OLDPWD)
variable, which holds the previous working directory (the one before the variable, which holds the previous working directory (the one before the
last `cd`). If `OLDPWD` is unset (never changed the directory), it is last `cd`). If `OLDPWD` is unset (never changed the directory), it is
not expanded. not expanded.
@ -107,4 +107,4 @@ not expanded.
## See also ## See also
- Internal: [Introduction to expansion and - Internal: [Introduction to expansion and
substitution](/syntax/expansion/intro) substitution](/syntax/expansion/intro.md)

View File

@ -5,9 +5,9 @@ FIXME to be continued!
Word splitting occurs once any of the following expansions are done (and Word splitting occurs once any of the following expansions are done (and
only then!) only then!)
- [Parameter expansion](/syntax/pe) - [Parameter expansion](/syntax/pe.md)
- [Command substitution](/syntax/expansion/cmdsubst) - [Command substitution](/syntax/expansion/cmdsubst.md)
- [Arithmetic expansion](/syntax/expansion/arith) - [Arithmetic expansion](/syntax/expansion/arith.md)
Bash will scan the results of these expansions for special `IFS` Bash will scan the results of these expansions for special `IFS`
characters that mark word boundaries. This is only done on results that characters that mark word boundaries. This is only done on results that
@ -43,5 +43,5 @@ solely responsible.
## See also ## See also
- [Introduction to expansion and substitution](/syntax/expansion/intro) - [Introduction to expansion and substitution](/syntax/expansion/intro.md)
- [Quoting and escaping](/syntax/quoting) - [Quoting and escaping](/syntax/quoting.md)

View File

@ -4,7 +4,7 @@ FIXME work in progress...
![](keywords>bash shell scripting syntax language behaviour executing execution) ![](keywords>bash shell scripting syntax language behaviour executing execution)
Nearly everything in [Bash grammar](/syntax/basicgrammar) can be broken Nearly everything in [Bash grammar](/syntax/basicgrammar.md) can be broken
down to a "simple command". The only thing Bash has to expand, evaluate down to a "simple command". The only thing Bash has to expand, evaluate
and execute is the simple command. and execute is the simple command.
@ -27,16 +27,16 @@ the simple command **from left to right**):
- variable assignments precede the command name and have the form - variable assignments precede the command name and have the form
`WORD=WORD` `WORD=WORD`
- redirections can appear anywhere in the simple command - redirections can appear anywhere in the simple command
2. The rest of the words are [expanded](/syntax/expansion/intro). If 2. The rest of the words are [expanded](/syntax/expansion/intro.md). If
any words remain after expansion, the first word is taken to be the any words remain after expansion, the first word is taken to be the
**name of the command** and the remaining words are the **name of the command** and the remaining words are the
**arguments**. **arguments**.
3. [Redirections](/syntax/redirection) are performed. 3. [Redirections](/syntax/redirection.md) are performed.
4. The text after the `=` in each variable assignment undergoes [tilde 4. The text after the `=` in each variable assignment undergoes [tilde
expansion](/syntax/expansion/tilde), [parameter expansion](/syntax/expansion/tilde.md), [parameter
expansion](/syntax/pe), [command expansion](/syntax/pe.md), [command
substitution](/syntax/expansion/cmdsubst), [arithmetic substitution](/syntax/expansion/cmdsubst.md), [arithmetic
expansion](/syntax/expansion/arith), and quote removal before being expansion](/syntax/expansion/arith.md), and quote removal before being
assigned to the variable. assigned to the variable.
If **no command name** results after expansion: If **no command name** results after expansion:
@ -119,6 +119,6 @@ FIXME to be continued
## See also ## See also
- Internal: [Redirection](/syntax/redirection) - Internal: [Redirection](/syntax/redirection.md)
- Internal: [Introduction to expansions and - Internal: [Introduction to expansions and
substitutions](/syntax/expansion/intro) substitutions](/syntax/expansion/intro.md)

View File

@ -4,14 +4,14 @@
A pattern is a **string description**. Bash uses them in various ways: A pattern is a **string description**. Bash uses them in various ways:
- [Pathname expansion](/syntax/expansion/globs) (Globbing - matching - [Pathname expansion](/syntax/expansion/globs.md) (Globbing - matching
filenames) filenames)
- Pattern matching in [conditional - Pattern matching in [conditional
expressions](/syntax/ccmd/conditional_expression) expressions](/syntax/ccmd/conditional_expression.md)
- [Substring removal](/syntax/pe#substring_removal) and [search and - [Substring removal](/syntax/pe.md#substring_removal) and [search and
replace](/syntax/pe#search_and_replace) in [Parameter replace](/syntax/pe.md#search_and_replace) in [Parameter
Expansion](/syntax/pe) Expansion](/syntax/pe.md)
- Pattern-based branching using the [case command](/syntax/ccmd/case) - Pattern-based branching using the [case command](/syntax/ccmd/case.md)
The pattern description language is relatively easy. Any character The pattern description language is relatively easy. Any character
that's not mentioned below matches itself. The `NUL` character may not that's not mentioned below matches itself. The `NUL` character may not
@ -75,7 +75,7 @@ Some simple examples using normal pattern matching:
## Extended pattern language ## Extended pattern language
If you set the [shell option](/internals/shell_options) `extglob`, Bash If you set the [shell option](/internals/shell_options.md) `extglob`, Bash
understands some powerful patterns. A `<PATTERN-LIST>` is one or more understands some powerful patterns. A `<PATTERN-LIST>` is one or more
patterns, separated by the pipe-symbol (`PATTERN|PATTERN`). patterns, separated by the pipe-symbol (`PATTERN|PATTERN`).
@ -99,13 +99,13 @@ patterns, separated by the pipe-symbol (`PATTERN|PATTERN`).
| option | classification | description | | option | classification | description |
|-------------------|-------------------------------------|-------------------------------------------------------------------------------| |-------------------|-------------------------------------|-------------------------------------------------------------------------------|
| `dotglob` | [globbing](/syntax/expansion/globs) | see [Pathname expansion customization](/syntax/expansion/globs#Customization) | | `dotglob` | [globbing](/syntax/expansion/globs.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
| `extglob` | global | enable/disable extended pattern matching language, as described above | | `extglob` | global | enable/disable extended pattern matching language, as described above |
| `failglob` | [globbing](/syntax/expansion/globs) | see [Pathname expansion customization](/syntax/expansion/globs#Customization) | | `failglob` | [globbing](/syntax/expansion/globs.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
| `nocaseglob` | [globbing](/syntax/expansion/globs) | see [Pathname expansion customization](/syntax/expansion/globs#Customization) | | `nocaseglob` | [globbing](/syntax/expansion/globs.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
| `nocasematch` | pattern/string matching | perform pattern matching without regarding the case of individual letters | | `nocasematch` | pattern/string matching | perform pattern matching without regarding the case of individual letters |
| `nullglob` | [globbing](/syntax/expansion/globs) | see [Pathname expansion customization](/syntax/expansion/globs#Customization) | | `nullglob` | [globbing](/syntax/expansion/globs.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
| `globasciiranges` | [globbing](/syntax/expansion/globs) | see [Pathname expansion customization](/syntax/expansion/globs#Customization) | | `globasciiranges` | [globbing](/syntax/expansion/globs.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
## Bugs and Portability considerations ## Bugs and Portability considerations

View File

@ -9,7 +9,7 @@ is an entity that stores values and is referenced by a **name**, a
**number** or a **special symbol**. **number** or a **special symbol**.
- parameters referenced by a name are called **variables** (this also - parameters referenced by a name are called **variables** (this also
applies to [arrays](/syntax/arrays)) applies to [arrays](/syntax/arrays.md))
- parameters referenced by a number are called **positional parameters** - parameters referenced by a number are called **positional parameters**
and reflect the arguments given to a shell and reflect the arguments given to a shell
- parameters referenced by a **special symbol** are auto-set parameters - parameters referenced by a **special symbol** are auto-set parameters
@ -25,7 +25,7 @@ check what it can be, try the overview section below!
**Arrays** can be special cases for parameter expansion, every **Arrays** can be special cases for parameter expansion, every
applicable description mentions arrays below. Please also see the applicable description mentions arrays below. Please also see the
[article about arrays](/syntax/arrays). [article about arrays](/syntax/arrays.md).
For a more technical view what a parameter is and which types exist, For a more technical view what a parameter is and which types exist,
[see the dictionary entry for "parameter"](/dict/terms/parameter). [see the dictionary entry for "parameter"](/dict/terms/parameter).
@ -113,7 +113,7 @@ positional parameters (arguments to a script) beyond `$9`:
### Simple usage: Arrays ### Simple usage: Arrays
See also the [article about general array syntax](/syntax/arrays) See also the [article about general array syntax](/syntax/arrays.md)
For arrays you always need the braces. The arrays are expanded by For arrays you always need the braces. The arrays are expanded by
individual indexes or mass arguments. An individual index behaves like a individual indexes or mass arguments. An individual index behaves like a
@ -178,7 +178,7 @@ conflicts with ksh-like shells which have the more powerful
"name-reference" form of indirection, where the exact same syntax is "name-reference" form of indirection, where the exact same syntax is
used to expand to the name of the variable being referenced. used to expand to the name of the variable being referenced.
Indirect references to [array names](/syntax/arrays) are also possible Indirect references to [array names](/syntax/arrays.md) are also possible
since the Bash 3 series (exact version unknown), but undocumented. See since the Bash 3 series (exact version unknown), but undocumented. See
[syntax/arrays#indirection](syntax/arrays#indirection) for details. [syntax/arrays#indirection](syntax/arrays#indirection) for details.
@ -237,7 +237,7 @@ names or titles. Just assign it to an array:
`declare -a title=(my hello world john smith)` `declare -a title=(my hello world john smith)`
For [array](/syntax/arrays) expansion, the case modification applies to For [array](/syntax/arrays.md) expansion, the case modification applies to
**every expanded element, no matter if you expand an individual index or **every expanded element, no matter if you expand an individual index or
mass-expand** the whole array using `@` or `*` subscripts. Some mass-expand** the whole array using `@` or `*` subscripts. Some
examples: examples:
@ -274,7 +274,7 @@ This will show all defined variable names (not values!) beginning with
$ echo ${!BASH*} $ echo ${!BASH*}
BASH BASH_ARGC BASH_ARGV BASH_COMMAND BASH_LINENO BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION BASH BASH_ARGC BASH_ARGV BASH_COMMAND BASH_LINENO BASH_SOURCE BASH_SUBSHELL BASH_VERSINFO BASH_VERSION
This list will also include [array names](/syntax/arrays). This list will also include [array names](/syntax/arrays.md).
## Substring removal ## Substring removal
@ -289,7 +289,7 @@ This list will also include [array names](/syntax/arrays).
This one can **expand only a part** of a parameter's value, **given a This one can **expand only a part** of a parameter's value, **given a
pattern to describe what to remove** from the string. The pattern is pattern to describe what to remove** from the string. The pattern is
interpreted just like a pattern to describe a filename to match interpreted just like a pattern to describe a filename to match
(globbing). See [Pattern matching](/syntax/pattern) for more. (globbing). See [Pattern matching](/syntax/pattern.md) for more.
Example string (*just a quote from a big man*): Example string (*just a quote from a big man*):
@ -299,7 +299,7 @@ Example string (*just a quote from a big man*):
`${PARAMETER#PATTERN}` and `${PARAMETER##PATTERN}` `${PARAMETER#PATTERN}` and `${PARAMETER##PATTERN}`
This form is to remove the described [pattern](/syntax/pattern) trying This form is to remove the described [pattern](/syntax/pattern.md) trying
to **match it from the beginning of the string**. The operator "`#`" to **match it from the beginning of the string**. The operator "`#`"
will try to remove the shortest text matching the pattern, while "`##`" will try to remove the shortest text matching the pattern, while "`##`"
tries to do it with the longest text matching. Look at the following tries to do it with the longest text matching. Look at the following
@ -352,7 +352,7 @@ on your needs, you might need to adjust shortest/longest match.
### Substring removal: Arrays ### Substring removal: Arrays
As for most parameter expansion features, working on As for most parameter expansion features, working on
[arrays](/syntax/arrays) **will handle each expanded element**, for [arrays](/syntax/arrays.md) **will handle each expanded element**, for
individual expansion and also for mass expansion. individual expansion and also for mass expansion.
Simple example, removing a trailing `is` from all array elements (on Simple example, removing a trailing `is` from all array elements (on
@ -377,7 +377,7 @@ All other variants of this expansion behave the same.
`${PARAMETER//PATTERN}` `${PARAMETER//PATTERN}`
This one can substitute (*replace*) a substring [matched by a This one can substitute (*replace*) a substring [matched by a
pattern](/syntax/pattern), on expansion time. The matched substring will pattern](/syntax/pattern.md), on expansion time. The matched substring will
be entirely removed and the given string will be inserted. Again some be entirely removed and the given string will be inserted. Again some
example string for the tests: example string for the tests:
@ -437,7 +437,7 @@ specifying an empty replacement:
### Search and replace: Arrays ### Search and replace: Arrays
This parameter expansion type applied to [arrays](/syntax/arrays) This parameter expansion type applied to [arrays](/syntax/arrays.md)
**applies to all expanded elements**, no matter if an individual element **applies to all expanded elements**, no matter if an individual element
is expanded, or all elements using the mass expansion syntaxes. is expanded, or all elements using the mass expansion syntaxes.
@ -471,7 +471,7 @@ There's not much to say about it, mh?
### (String) length: Arrays ### (String) length: Arrays
For [arrays](/syntax/arrays), this expansion type has two meanings: For [arrays](/syntax/arrays.md), this expansion type has two meanings:
- For **individual** elements, it reports the string length of the - For **individual** elements, it reports the string length of the
element (as for every "normal" parameter) element (as for every "normal" parameter)
@ -506,7 +506,7 @@ is negative, it's taken as a second offset into the string, counting
from the end of the string. from the end of the string.
`OFFSET` and `LENGTH` can be **any** [arithmetic `OFFSET` and `LENGTH` can be **any** [arithmetic
expression](/syntax/arith_expr). **Take care:** The `OFFSET` starts at expression](/syntax/arith_expr.md). **Take care:** The `OFFSET` starts at
0, not at 1! 0, not at 1!
Example string (a quote from a big man): Example string (a quote from a big man):
@ -543,7 +543,7 @@ the colon:
${MYSTRING:(-10):5} ${MYSTRING:(-10):5}
Why? Because it's interpreted as the parameter expansion syntax to [use Why? Because it's interpreted as the parameter expansion syntax to [use
a default value](/syntax/pe#use_a_default_value). a default value](/syntax/pe.md#use_a_default_value).
### Negative Length Value ### Negative Length Value
@ -557,11 +557,11 @@ then:
`<del>Be liberal </del>in what you accept, and conservative<del> in what you send</del>` `<del>Be liberal </del>in what you accept, and conservative<del> in what you send</del>`
This works since Bash 4.2-alpha, see also This works since Bash 4.2-alpha, see also
[bashchanges](/scripting/bashchanges). [bashchanges](/scripting/bashchanges.md).
### Substring/Element expansion: Arrays ### Substring/Element expansion: Arrays
For [arrays](/syntax/arrays), this expansion type has again 2 meanings: For [arrays](/syntax/arrays.md), this expansion type has again 2 meanings:
- For **individual** elements, it expands to the specified substring (as - For **individual** elements, it expands to the specified substring (as
for every “normal” parameter) for every “normal” parameter)
@ -608,7 +608,7 @@ gender. Note that the default value is **used on expansion time**, it is
### Use a default value: Arrays ### Use a default value: Arrays
For [arrays](/syntax/arrays), the behaviour is very similar. Again, you For [arrays](/syntax/arrays.md), the behaviour is very similar. Again, you
have to make a difference between expanding an individual element by a have to make a difference between expanding an individual element by a
given index and mass-expanding the array using the `@` and `*` given index and mass-expanding the array using the `@` and `*`
subscripts. subscripts.
@ -669,7 +669,7 @@ Example code (please try the example cases yourself):
`${PARAMETER=WORD}` `${PARAMETER=WORD}`
This one works like the [using default This one works like the [using default
values](/syntax/pe#use_a_default_value), but the default text you give values](/syntax/pe.md#use_a_default_value), but the default text you give
is not only expanded, but also **assigned** to the parameter, if it was is not only expanded, but also **assigned** to the parameter, if it was
unset or null. Equivalent to using a default value, when you omit the unset or null. Equivalent to using a default value, when you omit the
`:` (colon), as shown in the second form, the default value will only be `:` (colon), as shown in the second form, the default value will only be
@ -691,7 +691,7 @@ Let's change our code example from above:
### Assign a default value: Arrays ### Assign a default value: Arrays
For [arrays](/syntax/arrays) this expansion type is limited. For an For [arrays](/syntax/arrays.md) this expansion type is limited. For an
individual index, it behaves like for a "normal" parameter, the default individual index, it behaves like for a "normal" parameter, the default
value is assigned to this one element. The mass-expansion subscripts `@` value is assigned to this one element. The mass-expansion subscripts `@`
and `*` **can not be used here** because it's not possible to assign to and `*` **can not be used here** because it's not possible to assign to
@ -740,7 +740,7 @@ if variables you need (and that can be empty) are undefined:
### Use an alternate value: Arrays ### Use an alternate value: Arrays
Similar to the cases for [arrays](/syntax/arrays) to expand to a default Similar to the cases for [arrays](/syntax/arrays.md) to expand to a default
value, this expansion behaves like for a "normal" parameter when using value, this expansion behaves like for a "normal" parameter when using
individual array elements by index, but reacts differently when using individual array elements by index, but reacts differently when using
the mass-expansion subscripts `@` and `*`: the mass-expansion subscripts `@` and `*`:
@ -816,8 +816,8 @@ Removing the first 6 characters from a text string:
`${arr[@]}`, `$*`, and `${arr[*]}` when `${arr[@]}`, `$*`, and `${arr[*]}` when
[IFS](http://mywiki.wooledge.org/IFS) is set to null. POSIX is unclear [IFS](http://mywiki.wooledge.org/IFS) is set to null. POSIX is unclear
about the expected behavior. A null IFS causes both [word about the expected behavior. A null IFS causes both [word
splitting](/syntax/expansion/wordsplit) and [pathname splitting](/syntax/expansion/wordsplit.md) and [pathname
expansion](/syntax/expansion/globs) to behave randomly. Since there expansion](/syntax/expansion/globs.md) to behave randomly. Since there
are few good reasons to leave `IFS` set to null for more than the are few good reasons to leave `IFS` set to null for more than the
duration of a command or two, and even fewer to expand `$@` and `$*` duration of a command or two, and even fewer to expand `$@` and `$*`
unquoted, this should be a rare issue. **Always quote unquoted, this should be a rare issue. **Always quote
@ -1040,5 +1040,5 @@ the difference may introduce a possible compatibility problem.
## See also ## See also
- Internal: [Introduction to expansion and - Internal: [Introduction to expansion and
substitution](/syntax/expansion/intro) substitution](/syntax/expansion/intro.md)
- Internal: [Arrays](/syntax/arrays) - Internal: [Arrays](/syntax/arrays.md)

View File

@ -71,14 +71,14 @@ below).
Inside a weak-quoted string there's **no special interpretion of**: Inside a weak-quoted string there's **no special interpretion of**:
- spaces as word-separators (on inital command line splitting and on - spaces as word-separators (on inital command line splitting and on
[word splitting](/syntax/expansion/wordsplit)!) [word splitting](/syntax/expansion/wordsplit.md)!)
- single-quotes to introduce strong-quoting (see below) - single-quotes to introduce strong-quoting (see below)
- characters for pattern matching - characters for pattern matching
- tilde expansion - tilde expansion
- pathname expansion - pathname expansion
- process substitution - process substitution
Everything else, especially [parameter expansion](/syntax/pe), is Everything else, especially [parameter expansion](/syntax/pe.md), is
performed! performed!
ls -l "*" ls -l "*"
@ -197,7 +197,7 @@ documentation](http://www.gnu.org/software/gettext/manual/html_node/bash.html)
### String lists in for-loops ### String lists in for-loops
The [classic for loop](/syntax/ccmd/classic_for) uses a list of words to The [classic for loop](/syntax/ccmd/classic_for.md) uses a list of words to
iterate through. The list can also be in a variable: iterate through. The list can also be in a variable:
mylist="DOG CAT BIRD HORSE" mylist="DOG CAT BIRD HORSE"
@ -221,7 +221,7 @@ is seen as **one word**. The for loop iterates exactly one time, with
### Working out the test-command ### Working out the test-command
The command `test` or `[ ... ]` ([the classic test The command `test` or `[ ... ]` ([the classic test
command](/commands/classictest)) is an ordinary command, so ordinary command](/commands/classictest.md)) is an ordinary command, so ordinary
syntax rules apply. Let's take string comparison as an example: syntax rules apply. Let's take string comparison as an example:
[ WORD = WORD ] [ WORD = WORD ]
@ -259,13 +259,13 @@ Now the command has three parameters, which makes sense for a binary
(two argument) operator. (two argument) operator.
**<u>Hint:</u>** Inside the [conditional **<u>Hint:</u>** Inside the [conditional
expression](/syntax/ccmd/conditional_expression) (`[[ ]]`) Bash doesn't expression](/syntax/ccmd/conditional_expression.md) (`[[ ]]`) Bash doesn't
perform word splitting, and thus you don't need to quote your variable perform word splitting, and thus you don't need to quote your variable
references - they are always seen as "one word". references - they are always seen as "one word".
## See also ## See also
- Internal: [Some words about words...](/syntax/words) - Internal: [Some words about words...](/syntax/words.md)
- Internal: [Word splitting](/syntax/expansion/wordsplit) - Internal: [Word splitting](/syntax/expansion/wordsplit.md)
- Internal: [Introduction to expansions and - Internal: [Introduction to expansions and
substitutions](/syntax/expansion/intro) substitutions](/syntax/expansion/intro.md)

View File

@ -5,7 +5,7 @@ Redirection makes it possible to control where the output of a command
goes to, and where the input of a command comes from. It's a mighty tool goes to, and where the input of a command comes from. It's a mighty tool
that, together with pipelines, makes the shell powerful. The redirection that, together with pipelines, makes the shell powerful. The redirection
operators are checked whenever a [simple command is about to be operators are checked whenever a [simple command is about to be
executed](/syntax/grammar/parser_exec). executed](/syntax/grammar/parser_exec.md).
Under normal circumstances, there are 3 files open, accessible by the Under normal circumstances, there are 3 files open, accessible by the
file descriptors 0, 1 and 2, all connected to your terminal: file descriptors 0, 1 and 2, all connected to your terminal:
@ -79,7 +79,7 @@ This redirects the file descriptor number `N` to the target `TARGET`. If
**truncated** before writing starts. **truncated** before writing starts.
If the option `noclobber` is set with [the set If the option `noclobber` is set with [the set
builtin](/commands/builtin/set), with cause the redirection to fail, builtin](/commands/builtin/set.md), with cause the redirection to fail,
when `TARGET` names a regular file that already exists. You can manually when `TARGET` names a regular file that already exists. You can manually
override that behaviour by forcing overwrite with the redirection override that behaviour by forcing overwrite with the redirection
operator `>|` instead of `>`. operator `>|` instead of `>`.
@ -108,7 +108,7 @@ Since Bash4, there's `&>>TARGET`, which is equivalent to
\<wrap center important\>This syntax is deprecated and should not be \<wrap center important\>This syntax is deprecated and should not be
used. See the page about [obsolete and deprecated used. See the page about [obsolete and deprecated
syntax](/scripting/obsolete).\</wrap\> syntax](/scripting/obsolete.md).\</wrap\>
## Appending redirected output and error output ## Appending redirected output and error output
@ -160,9 +160,9 @@ used to mark the end of input later:
As you see, substitutions are possible. To be precise, the following As you see, substitutions are possible. To be precise, the following
substitutions and expansions are performed in the here-document data: substitutions and expansions are performed in the here-document data:
- [Parameter expansion](/syntax/pe) - [Parameter expansion](/syntax/pe.md)
- [Command substitution](/syntax/expansion/cmdsubst) - [Command substitution](/syntax/expansion/cmdsubst.md)
- [Arithmetic expansion](/syntax/expansion/arith) - [Arithmetic expansion](/syntax/expansion/arith.md)
You can avoid that by quoting the tag: You can avoid that by quoting the tag:
@ -238,10 +238,10 @@ How to make a program quiet (assuming all output goes to `STDOUT` and
## See also ## See also
- Internal: [Illustrated Redirection - Internal: [Illustrated Redirection
Tutorial](/howto/redirection_tutorial) Tutorial](/howto/redirection_tutorial.md)
- Internal: [The noclobber option](/commands/builtin/set#tag_noclobber) - Internal: [The noclobber option](/commands/builtin/set.md#tag_noclobber)
- Internal: [The exec builtin command](/commands/builtin/exec) - Internal: [The exec builtin command](/commands/builtin/exec.md)
- Internal: [Simple commands parsing and - Internal: [Simple commands parsing and
execution](/syntax/grammar/parser_exec) execution](/syntax/grammar/parser_exec.md)
- Internal: [Process substitution syntax](/syntax/expansion/proc_subst) - Internal: [Process substitution syntax](/syntax/expansion/proc_subst.md)
- Internal: [Obsolete and deprecated syntax](/scripting/obsolete) - Internal: [Obsolete and deprecated syntax](/scripting/obsolete.md)

View File

@ -15,7 +15,7 @@
<td><code>*</code></td> <td><code>*</code></td>
<td>asterisk</td> <td>asterisk</td>
<td>The positional parameters starting from the first. When used inside <td>The positional parameters starting from the first. When used inside
doublequotes (see <a href="/syntax/quoting">quoting</a>), like doublequotes (see <a href="/syntax/quoting.md">quoting</a>), like
<code>"$*"</code>, it expands to all positional parameters <em>as one <code>"$*"</code>, it expands to all positional parameters <em>as one
word</em>, delimited by the first character of the <code>IFS</code> word</em>, delimited by the first character of the <code>IFS</code>
variable (a space in this example): <code>"$1 $2 $3 $4"</code>.<br /> variable (a space in this example): <code>"$1 $2 $3 $4"</code>.<br />
@ -26,26 +26,26 @@ delimiter.<br />
When used unquoted, it will just expand to the strings, one by one, not When used unquoted, it will just expand to the strings, one by one, not
preserving the word boundaries (i.e. word splitting will split the text preserving the word boundaries (i.e. word splitting will split the text
again, if it contains <code>IFS</code> characters.<br /> again, if it contains <code>IFS</code> characters.<br />
See also the <a href="/scripting/posparams">scripting article about See also the <a href="/scripting/posparams.md">scripting article about
handling positional parameters</a>.</td> handling positional parameters</a>.</td>
</tr> </tr>
<tr class="even"> <tr class="even">
<td><code>@</code></td> <td><code>@</code></td>
<td>at-sign</td> <td>at-sign</td>
<td>The positional parameters starting from the first. When used inside <td>The positional parameters starting from the first. When used inside
doublequotes (see <a href="/syntax/quoting">quoting</a>), like doublequotes (see <a href="/syntax/quoting.md">quoting</a>), like
<code>"$@"</code>, it expands all positional parameters <em>as separate <code>"$@"</code>, it expands all positional parameters <em>as separate
words</em>: <code>"$1" "$2" "$3" "$4"</code><br /> words</em>: <code>"$1" "$2" "$3" "$4"</code><br />
Without doublequotes, the behaviour is like the one of <code>*</code> Without doublequotes, the behaviour is like the one of <code>*</code>
without doublequotes.<br /> without doublequotes.<br />
See also the <a href="/scripting/posparams">scripting article about See also the <a href="/scripting/posparams.md">scripting article about
handling positional parameters</a>.</td> handling positional parameters</a>.</td>
</tr> </tr>
<tr class="odd"> <tr class="odd">
<td><code>#</code></td> <td><code>#</code></td>
<td>hash mark</td> <td>hash mark</td>
<td>Number of positional parameters (decimal)<br /> <td>Number of positional parameters (decimal)<br />
See also the <a href="/scripting/posparams">scripting article about See also the <a href="/scripting/posparams.md">scripting article about
handling positional parameters</a>.</td> handling positional parameters</a>.</td>
</tr> </tr>
<tr class="even"> <tr class="even">
@ -58,7 +58,7 @@ handling positional parameters</a>.</td>
<td><code>-</code></td> <td><code>-</code></td>
<td>dash</td> <td>dash</td>
<td>Current option flags set by the shell itself, on invocation, or <td>Current option flags set by the shell itself, on invocation, or
using the <a href="/commands/builtin/set">set builtin command</a>. It's using the <a href="/commands/builtin/set.md">set builtin command</a>. It's
just a set of characters, like <code>himB</code> for <code>h</code>, just a set of characters, like <code>himB</code> for <code>h</code>,
<code>i</code>, <code>m</code> and <code>B</code>.</td> <code>i</code>, <code>m</code> and <code>B</code>.</td>
</tr> </tr>
@ -66,7 +66,7 @@ just a set of characters, like <code>himB</code> for <code>h</code>,
<td><code>$</code></td> <td><code>$</code></td>
<td>dollar-sign</td> <td>dollar-sign</td>
<td>The process ID (PID) of the shell. In an <a <td>The process ID (PID) of the shell. In an <a
href="/syntax/ccmd/grouping_subshell">explicit subshell</a> it expands href="/syntax/ccmd/grouping_subshell.md">explicit subshell</a> it expands
to the PID of the current "main shell", not the subshell. This is to the PID of the current "main shell", not the subshell. This is
different from <code>$BASHPID</code>!</td> different from <code>$BASHPID</code>!</td>
</tr> </tr>
@ -125,7 +125,7 @@ Bash.
A colon-separated list of enabled shell options. A colon-separated list of enabled shell options.
Each word in the list is a valid argument for the `-s` option to the Each word in the list is a valid argument for the `-s` option to the
[shopt builtin command](/commands/builtin/shopt). The options appearing [shopt builtin command](/commands/builtin/shopt.md). The options appearing
in `BASHOPTS` are those reported as on by `shopt`. If this variable is in `BASHOPTS` are those reported as on by `shopt`. If this variable is
in the environment when Bash starts up, each shell option in the list in the environment when Bash starts up, each shell option in the list
will be enabled before reading any startup files. will be enabled before reading any startup files.
@ -525,7 +525,7 @@ element of `FUNCNAME` has corresponding elements in `BASH_LINENO` and
`BASH_SOURCE` to describe the call stack. For instance, `BASH_SOURCE` to describe the call stack. For instance,
`${FUNCNAME[$i]}` was called from the file `${BASH_SOURCE[$i+1]}` at `${FUNCNAME[$i]}` was called from the file `${BASH_SOURCE[$i+1]}` at
line number `${BASH_LINENO[$i]}`. The [caller builtin line number `${BASH_LINENO[$i]}`. The [caller builtin
command](/commands/builtin/caller) displays the current call stack using command](/commands/builtin/caller.md) displays the current call stack using
this information. this information.
This variable exists only when a shell function is executing. This variable exists only when a shell function is executing.
@ -626,7 +626,7 @@ Example content:
| Set by Bash: | yes | Default: | n/a | | Set by Bash: | yes | Default: | n/a |
An array variable created to hold the text read by the [mapfile builtin An array variable created to hold the text read by the [mapfile builtin
command](/commands/builtin/mapfile) when no variable name is supplied. command](/commands/builtin/mapfile.md) when no variable name is supplied.
### OLDPWD ### OLDPWD
@ -739,10 +739,10 @@ with `bind -x`.
| Variable: | `REPLY` | Since: | unknown | | Variable: | `REPLY` | Since: | unknown |
|:-------------|:-----------------------------------------------------------|:-----------|:--------| |:-------------|:-----------------------------------------------------------|:-----------|:--------|
| Type: | normal variable | Read-only: | no | | Type: | normal variable | Read-only: | no |
| Set by Bash: | only by the [read builtin command](/commands/builtin/read) | Default: | n/a | | Set by Bash: | only by the [read builtin command](/commands/builtin/read.md) | Default: | n/a |
Set to the line of input read by the [read builtin Set to the line of input read by the [read builtin
command](/commands/builtin/read) when no arguments are supplied that command](/commands/builtin/read.md) when no arguments are supplied that
name target variables. name target variables.
### SECONDS ### SECONDS
@ -769,7 +769,7 @@ is subsequently reset.
A colon-separated list of enabled shell options. Each word in the list A colon-separated list of enabled shell options. Each word in the list
is a valid argument for the `-o` option to the [set builtin is a valid argument for the `-o` option to the [set builtin
command](/commands/builtin/set). The options appearing in `SHELLOPTS` command](/commands/builtin/set.md). The options appearing in `SHELLOPTS`
are those reported as on by `set -o`. are those reported as on by `set -o`.
If this variable is in the environment when Bash starts up, each shell If this variable is in the environment when Bash starts up, each shell
@ -807,9 +807,9 @@ If this parameter is set when Bash is executing a shell script, its
value is interpreted as a filename containing commands to initialize the value is interpreted as a filename containing commands to initialize the
shell, as in `~/.bashrc`. The value of `BASH_ENV` is subjected to shell, as in `~/.bashrc`. The value of `BASH_ENV` is subjected to
- [parameter expansion](/syntax/pe) - [parameter expansion](/syntax/pe.md)
- [command substitution](/syntax/expansion/cmdsubst) - [command substitution](/syntax/expansion/cmdsubst.md)
- [arithmetic expansion](/syntax/expansion/arith) - [arithmetic expansion](/syntax/expansion/arith.md)
before being interpreted as a file name. before being interpreted as a file name.
@ -1060,7 +1060,7 @@ The home directory of the current user.
The default argument for the [cd builtin command](/commands/builtin/cd). The default argument for the [cd builtin command](/commands/builtin/cd).
The value of this variable is also used when performing [tilde The value of this variable is also used when performing [tilde
expansion](/syntax/expansion/tilde). expansion](/syntax/expansion/tilde.md).
### HOSTFILE ### HOSTFILE
@ -1438,7 +1438,7 @@ A trailing newline is added when the format string is displayed.
| Set by Bash: | no | Default: | n/a | | Set by Bash: | no | Default: | n/a |
If set to a value greater than zero, `TMOUT` is treated as the default If set to a value greater than zero, `TMOUT` is treated as the default
timeout for the [read builtin command](/commands/builtin/read). timeout for the [read builtin command](/commands/builtin/read.md).
The [select command](/commands/builtin/select) terminates if input does The [select command](/commands/builtin/select) terminates if input does
not arrive after `TMOUT` seconds when input is coming from a terminal. not arrive after `TMOUT` seconds when input is coming from a terminal.

View File

@ -89,7 +89,7 @@ take care of the spaces. But Bash also does another type of splitting.
## Word splitting ## Word splitting
For a more technical description, please read the [article about word For a more technical description, please read the [article about word
splitting](/syntax/expansion/wordsplit)! splitting](/syntax/expansion/wordsplit.md)!
The first kind of splitting is done to parse the command line into The first kind of splitting is done to parse the command line into
separate tokens. This is what was described above, it's a pure **command separate tokens. This is what was described above, it's a pure **command
@ -138,9 +138,9 @@ the command line"):
| Word 1 | Word 2 | Word 3 | Word 4 | Word 5 | Word 6 | | Word 1 | Word 2 | Word 3 | Word 4 | Word 5 | Word 6 |
| `echo` | `The` | `file` | `is` | `named` | `$MYFILE` | | `echo` | `The` | `file` | `is` | `named` | `$MYFILE` |
A [parameter/variable expansion](/syntax/pe) is part of that command A [parameter/variable expansion](/syntax/pe.md) is part of that command
line, Bash will perform the substitution, and the [word line, Bash will perform the substitution, and the [word
splitting](/syntax/expansion/wordsplit) on the results: splitting](/syntax/expansion/wordsplit.md) on the results:
| Word splitting after substitution: | | | | | | | | Word splitting after substitution: | | | | | | |
|------------------------------------|--------|--------|--------|---------|--------|------------| |------------------------------------|--------|--------|--------|---------|--------|------------|
@ -158,7 +158,7 @@ Now let's imagine we quoted `$MYFILE`, the command line now looks like:
***Bold Text*72i love this world**===== See also ===== ***Bold Text*72i love this world**===== See also =====
- Internal: [Quoting and character escaping](/syntax/quoting) - Internal: [Quoting and character escaping](/syntax/quoting.md)
- Internal: [Word splitting](/syntax/expansion/wordsplit) - Internal: [Word splitting](/syntax/expansion/wordsplit.md)
- Internal: [Introduction to expansions and - Internal: [Introduction to expansions and
substitutions](/syntax/expansion/intro) substitutions](/syntax/expansion/intro.md)

View File

@ -46,7 +46,7 @@ bash I found here:
- <http://linux.derkeiler.com/Mailing-Lists/Debian/2006-08/msg00462.html> - <http://linux.derkeiler.com/Mailing-Lists/Debian/2006-08/msg00462.html>
> added to [the for-loop-article](/syntax/ccmd/classic_for) as example, > added to [the for-loop-article](/syntax/ccmd/classic_for.md) as example,
> but also made some critical comments; thanks --- Jan > but also made some critical comments; thanks --- Jan
### Getopts tutorial ### Getopts tutorial