mirror of
https://github.com/rawiriblundell/wiki.bash-hackers.org
synced 2024-12-23 21:40:39 +01:00
Correct internal links across all .md files
This commit is contained in:
parent
39591d2ff9
commit
cb82c31d36
34
bash4.md
34
bash4.md
@ -1,11 +1,11 @@
|
||||
# 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
|
||||
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.
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
@ -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
|
||||
callback, for example to display a progress bar.
|
||||
|
||||
See: [mapfile](/commands/builtin/mapfile)
|
||||
See: [mapfile](/commands/builtin/mapfile.md)
|
||||
|
||||
### 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
|
||||
pattern instead of terminating the whole execution.
|
||||
|
||||
See [case](/syntax/ccmd/case)
|
||||
See [case](/syntax/ccmd/case.md)
|
||||
|
||||
### 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
|
||||
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
|
||||
|
||||
@ -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
|
||||
zeros when requesting a row of numbers.
|
||||
|
||||
See [brace](/syntax/expansion/brace)
|
||||
See [brace](/syntax/expansion/brace.md)
|
||||
|
||||
### Parameter Expansion
|
||||
|
||||
@ -119,7 +119,7 @@ On expansion time you can modify the syntax by adding operators to the
|
||||
parameter name.
|
||||
|
||||
See [Case modification on parameter
|
||||
expansion](/syntax/pe#case_modification)
|
||||
expansion](/syntax/pe.md#case_modification)
|
||||
|
||||
### Substring expansion
|
||||
|
||||
@ -140,7 +140,7 @@ current level.
|
||||
The new shell option `dirspell` enables spelling corrections on
|
||||
directory names during globbing.
|
||||
|
||||
See [globs](/syntax/expansion/globs)
|
||||
See [globs](/syntax/expansion/globs.md)
|
||||
|
||||
## Associative Arrays
|
||||
|
||||
@ -156,7 +156,7 @@ something like
|
||||
ASSOC[Hello]="second element"
|
||||
ASSOC[Peter Pan]="A weird guy"
|
||||
|
||||
See [arrays](/syntax/arrays)
|
||||
See [arrays](/syntax/arrays.md)
|
||||
|
||||
## Redirection
|
||||
|
||||
@ -167,17 +167,17 @@ good old `>>FILE 2>&1` notation.
|
||||
The parser now understands `|&` as a synonym for `2>&1 |`, which
|
||||
redirects the standard error for a command through a pipe.
|
||||
|
||||
See [redirection](/syntax/redirection)
|
||||
See [redirection](/syntax/redirection.md)
|
||||
|
||||
## Interesting new shell variables
|
||||
|
||||
| Variable | Description |
|
||||
|----------------------------------------------------|--------------------------------------------------------------------------------|
|
||||
| [BASHPID](/syntax/shellvars#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 |
|
||||
| [FUNCNEST](/syntax/shellvars#FUNCNEST) | control the maximum number of shell function recursions |
|
||||
| [BASHPID](/syntax/shellvars.md#BASHPID) | contains the PID of the current shell (this is different than what `$$` does!) |
|
||||
| [PROMPT_DIRTRIM](/syntax/shellvars.md#PROMPT_DIRTRIM) | specifies the max. level of unshortened pathname elements in the prompt |
|
||||
| [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
|
||||
|
||||
@ -192,7 +192,7 @@ mentioned.
|
||||
| `globstar` | enables recursive globbing with `**` |
|
||||
| `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
|
||||
|
||||
@ -205,7 +205,7 @@ See [shell_options](/internals/shell_options)
|
||||
- The output target for the `xtrace` (`set -x`/`set +x`) feature is
|
||||
configurable **since Bash 4.1** (previously, it was fixed to
|
||||
`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
|
||||
- Bash 4.1 is able to log the history to syslog (only to be enabled at
|
||||
compile time in `config-top.h`)
|
||||
|
@ -155,6 +155,6 @@ for details. ksh93 namerefs are much more powerful than Bash's.
|
||||
|
||||
## See also
|
||||
|
||||
- [arrays](/syntax/arrays)
|
||||
- [readonly](/commands/builtin/readonly)
|
||||
- [unset](/commands/builtin/unset)
|
||||
- [arrays](/syntax/arrays.md)
|
||||
- [readonly](/commands/builtin/read.mdonly)
|
||||
- [unset](/commands/builtin/unset.md)
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
`echo` outputs it's args to stdout, separated by spaces, followed by a
|
||||
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
|
||||
(listed below) by default based on the current platform. `echo` doesn't
|
||||
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
|
||||
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
|
||||
ignore that `echo` even exists. If you must use `echo -e` and refuse
|
||||
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` 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
|
||||
option.
|
||||
|
||||
## See also
|
||||
|
||||
- [printf](/commands/builtin/printf)
|
||||
- [printf](/commands/builtin/printf.md)
|
||||
- <http://cfajohnson.com/shell/cus-faq.html#Q0b>
|
||||
|
@ -18,7 +18,7 @@ process.
|
||||
## Examples
|
||||
|
||||
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
|
||||
the `eval` command below it.
|
||||
|
||||
|
@ -28,7 +28,7 @@ shell without executing any program.
|
||||
- on redirection errors it returns 1, otherwise 0
|
||||
- on exec failures:
|
||||
- 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
|
||||
- in an interactive shell, `exec` returns failure
|
||||
|
||||
@ -82,4 +82,4 @@ exec >/var/adm/my.log 2>&1
|
||||
|
||||
## See also
|
||||
|
||||
- [redirection](/syntax/redirection)
|
||||
- [redirection](/syntax/redirection.md)
|
||||
|
@ -49,4 +49,4 @@ Set your default text editor (e.g. SublimeText):
|
||||
|
||||
## See also
|
||||
|
||||
- [declare](/commands/builtin/declare)
|
||||
- [declare](/commands/builtin/declare.md)
|
||||
|
@ -7,27 +7,27 @@
|
||||
## Description
|
||||
|
||||
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.
|
||||
|
||||
- 0 (TRUE) when `arg` evaluated to not 0 (arithmetic "true")
|
||||
- 1 (FALSE) when `arg` evaluated to 0 (arithmetic "false")
|
||||
|
||||
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 `((`.
|
||||
|
||||
## 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
|
||||
compound command. The arguments to `let` are therefore subject to all
|
||||
the same expansions and substitutions as any other simple command -
|
||||
requiring proper quoting and escaping - whereas the contents of `((`
|
||||
aren't subject to [word-splitting](/syntax/expansion/wordsplit) or
|
||||
[pathname expansion](/syntax/expansion/globs) (almost never desirable
|
||||
aren't subject to [word-splitting](/syntax/expansion/wordsplit.md) or
|
||||
[pathname expansion](/syntax/expansion/globs.md) (almost never desirable
|
||||
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`**.
|
||||
|
||||
$ let 'b = a' "(a += 3) + $((a = 1)), b++"
|
||||
@ -35,7 +35,7 @@ over `let`**.
|
||||
4 - 2 - 0
|
||||
|
||||
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++ ))
|
||||
$ echo "$a - $b - $?"
|
||||
@ -86,7 +86,7 @@ needed.
|
||||
- [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
|
||||
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.
|
||||
Unlike `let`, `expr` cannot assign directly to bash variables but
|
||||
instead returns a result on stdout. `expr` takes each operator it
|
||||
@ -104,7 +104,7 @@ needed.
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [arithmetic expansion](/syntax/expansion/arith)
|
||||
- Internal: [arithmetic expressions](/syntax/arith_expr)
|
||||
- Internal: [arithmetic expansion](/syntax/expansion/arith.md)
|
||||
- Internal: [arithmetic expressions](/syntax/arith_expr.md)
|
||||
|
||||
[^1]: ...
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
## 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:
|
||||
|
||||
- Usage outside of a function is an error. Both `declare` and `local`
|
||||
|
@ -214,7 +214,7 @@ each subsequent 2 iterations. The RETURN trap is unimportant.
|
||||
|
||||
## See also
|
||||
|
||||
- [arrays](/syntax/arrays)
|
||||
- [read](/commands/builtin/read) - If you don't know about this yet, why
|
||||
- [arrays](/syntax/arrays.md)
|
||||
- [read](/commands/builtin/read.md) - If you don't know about this yet, why
|
||||
are you reading this page?
|
||||
- <http://mywiki.wooledge.org/BashFAQ/001> - It's FAQ 1 for a reason.
|
||||
|
@ -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
|
||||
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
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
||||
## See also
|
||||
|
@ -16,13 +16,13 @@ Since Bash 4.3-alpha, `read` skips any `NUL` (ASCII code 0) characters
|
||||
in input.
|
||||
|
||||
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
|
||||
more words than variable names are present.
|
||||
|
||||
\<WRAP center round info 90%\> If no `<NAME>` is given, the whole line
|
||||
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
|
||||
other things!
|
||||
|
||||
@ -33,7 +33,7 @@ other things!
|
||||
\</WRAP\>
|
||||
|
||||
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
|
||||
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%\>
|
||||
|
||||
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
|
||||
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
|
||||
modify the parent shell. As a result, the variables `col1`, `col2` and
|
||||
`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
|
||||
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
|
||||
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"
|
||||
printf "col1: %s col2: %s\n" "$col1" "$col2"
|
||||
@ -264,6 +264,6 @@ date/time string are recognized correctly.
|
||||
|
||||
## 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
|
||||
|
@ -41,4 +41,4 @@ An argument of `--` disables further option processing.
|
||||
|
||||
## See also
|
||||
|
||||
- [declare](/commands/builtin/declare)
|
||||
- [declare](/commands/builtin/declare.md)
|
||||
|
@ -11,7 +11,7 @@ FIXME incomplete - text, examples, maybe extended description
|
||||
`set` is primarily made to
|
||||
|
||||
- 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 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. |
|
||||
| `-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`, `||`, `&&`) |
|
||||
| `-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. |
|
||||
| `-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). |
|
||||
@ -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. |
|
||||
| `-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. |
|
||||
| `-B` | `braceexpand` | The shell performs [brace expansion](/syntax/expansion/brace) 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) |
|
||||
| `-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.md) |
|
||||
| `-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. |
|
||||
| `-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 | |
|
||||
| | `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) |
|
||||
| | `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)** |
|
||||
| | `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. |
|
||||
@ -78,4 +78,4 @@ naturally.
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [The shopt builtin command](/commands/builtin/shopt)
|
||||
- Internal: [The shopt builtin command](/commands/builtin/shopt.md)
|
||||
|
@ -28,7 +28,7 @@ When you use `shift 1`, they will be changed to:
|
||||
| 2 | a |
|
||||
| 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.
|
||||
|
||||
If the number given is 0, no changes are made to the positional
|
||||
|
@ -1,6 +1,6 @@
|
||||
# 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
|
||||
behaviour of the shell.
|
||||
|
||||
@ -11,13 +11,13 @@ behaviour of the shell.
|
||||
## Description
|
||||
|
||||
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
|
||||
|
||||
| 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**. |
|
||||
| `-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 |
|
||||
@ -47,5 +47,5 @@ The `shopt` command is not portable accross different shells.
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [The set builtin command](/commands/builtin/set)
|
||||
- Internal: [List of shell options](/internals/shell_options)
|
||||
- Internal: [The set builtin command](/commands/builtin/set.md)
|
||||
- Internal: [List of shell options](/internals/shell_options.md)
|
||||
|
@ -34,7 +34,7 @@ Special events
|
||||
| `EXIT` | 0 | executed on shell exit |
|
||||
| `DEBUG` | | executed before every simple command |
|
||||
| `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
|
||||
|
||||
@ -68,5 +68,5 @@ Special events
|
||||
|
||||
## See also
|
||||
|
||||
- [the set command](/commands/builtin/set) for the `-e` (`errexit`)
|
||||
- [the set command](/commands/builtin/set.md) for the `-e` (`errexit`)
|
||||
option
|
||||
|
@ -175,5 +175,5 @@ using `unset`. Also, I prefer it as a matter of style.
|
||||
|
||||
## See also
|
||||
|
||||
- [declare](/commands/builtin/declare)
|
||||
- [unset](/commands/builtin/unset)
|
||||
- [declare](/commands/builtin/declare.md)
|
||||
- [unset](/commands/builtin/unset.md)
|
||||
|
@ -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
|
||||
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
|
||||
words...](/syntax/words)
|
||||
words...](/syntax/words.md)
|
||||
|
||||
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
|
||||
@ -147,7 +147,7 @@ ACLs, if the underlying filesystem/OS supports them.
|
||||
| \<TEST1\> **-o** \<TEST2\> | True, if either \<TEST1\> **or** \<TEST2\> is true (OR). |
|
||||
| **!** \<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 "\\"! |
|
||||
| **-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. |
|
||||
| **-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" ]`
|
||||
- **Note:** There are possibilities to make a difference if a variable
|
||||
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**
|
||||
- `test ! -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"**
|
||||
- `test $# -ge 1 -a "$1" = "Hello" || exit 1`
|
||||
- `[ $# -ge 1 ] && [ "$1" = "Hello" ] || exit 1` (see [lists
|
||||
description](/syntax/basicgrammar#lists))
|
||||
description](/syntax/basicgrammar.md#lists))
|
||||
|
||||
### 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" ]`),
|
||||
print its name:
|
||||
|
||||
@ -562,7 +562,7 @@ print its name:
|
||||
## See also
|
||||
|
||||
- Internal: [conditional
|
||||
expression](/syntax/ccmd/conditional_expression) (aka "the new test
|
||||
expression](/syntax/ccmd/conditional_expression.md) (aka "the new test
|
||||
command")
|
||||
|
||||
[^1]: \<rant\>Of course, one can wonder what is the use of including the
|
||||
|
@ -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`
|
||||
The implementation here is suboptimal in several ways, but the only
|
||||
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
|
||||
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,
|
||||
external commands, and pipes carry extra overhead when they launch, so
|
||||
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:
|
||||
|
||||
``` 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
|
||||
[Substring removal with parameter
|
||||
expansion](/syntax/pe#substring_removal):
|
||||
expansion](/syntax/pe.md#substring_removal):
|
||||
|
||||
``` bash
|
||||
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 "`&&`"
|
||||
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
|
||||
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
|
||||
happen again.
|
||||
|
||||
|
@ -23,7 +23,7 @@ are:
|
||||
|
||||
Some other methods to parse positional parameters - using neither
|
||||
**getopt** nor **getopts** - are described in: [How to handle positional
|
||||
parameters](/scripting/posparams).
|
||||
parameters](/scripting/posparams.md).
|
||||
|
||||
### Terminology
|
||||
|
||||
@ -88,9 +88,9 @@ which means [end of options](/dict/terms/end_of_options).
|
||||
|
||||
| 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** |
|
||||
| [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. |
|
||||
| [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. |
|
||||
| [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.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.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
|
||||
value-combinations which arent possible in normal operation).
|
||||
@ -133,7 +133,7 @@ messages.
|
||||
#### Custom arguments to parse
|
||||
|
||||
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 `"$@"`).
|
||||
|
||||
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
|
||||
|
||||
- Internal: [posparams](/scripting/posparams)
|
||||
- Internal: [case](/syntax/ccmd/case)
|
||||
- Internal: [while_loop](/syntax/ccmd/while_loop)
|
||||
- Internal: [posparams](/scripting/posparams.md)
|
||||
- Internal: [case](/syntax/ccmd/case.md)
|
||||
- Internal: [while_loop](/syntax/ccmd/while_loop.md)
|
||||
- POSIX
|
||||
[getopts(1)](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html#tag_20_54)
|
||||
and
|
||||
|
@ -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.
|
||||
|
||||
The shell-options can be set with the [shopt builtin
|
||||
command](/commands/builtin/shopt).
|
||||
command](/commands/builtin/shopt.md).
|
||||
|
||||
## Shell options
|
||||
|
||||
@ -78,8 +78,8 @@ stopped.
|
||||
|
||||
If set, Bash checks the window size after each command and, if
|
||||
necessary, updates the values of the variables
|
||||
[LINES](/syntax/shellvars#LINES) and
|
||||
[COLUMNS](/syntax/shellvars#COLUMNS).
|
||||
[LINES](/syntax/shellvars.md#LINES) and
|
||||
[COLUMNS](/syntax/shellvars.md#COLUMNS).
|
||||
|
||||
### cmdhist
|
||||
|
||||
@ -174,7 +174,7 @@ match a glob.
|
||||
| Shell mode: | all | Default: | off |
|
||||
|
||||
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
|
||||
|
||||
@ -209,7 +209,7 @@ If set, behavior intended for use by debuggers is enabled.
|
||||
|:------------|:----------|:---------|:------------|
|
||||
| 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
|
||||
configurations](#parser_configurations).
|
||||
|
||||
@ -220,7 +220,7 @@ configurations](#parser_configurations).
|
||||
| Shell mode: | all | Default: | on |
|
||||
|
||||
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
|
||||
configurations](#parser_configurations).
|
||||
|
||||
@ -240,7 +240,7 @@ result in an error message.
|
||||
| Shell mode: | interactive | Default: | on |
|
||||
|
||||
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
|
||||
the only possible completions. This option is enabled by default.
|
||||
|
||||
@ -280,7 +280,7 @@ message format".
|
||||
| Shell mode: | interactive (?) | Default: | off |
|
||||
|
||||
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.
|
||||
|
||||
### histreedit
|
||||
@ -324,7 +324,7 @@ interactive login shell exits.
|
||||
|:------------|:-----------------------|:---------|:--------|
|
||||
| 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.
|
||||
|
||||
### lastpipe
|
||||
@ -505,5 +505,5 @@ parsed:
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [shopt builtin command](/commands/builtin/shopt)
|
||||
- Internal: [set builtin command](/commands/builtin/set)
|
||||
- Internal: [shopt builtin command](/commands/builtin/shopt.md)
|
||||
- Internal: [set builtin command](/commands/builtin/set.md)
|
||||
|
@ -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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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.
|
||||
No other startup files are read. Hence, a non-interactive shell doesn't
|
||||
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 environment variable
|
||||
[POSIXLY_CORRECT](/syntax/shellvars#POSIXLY_CORRECT) is set
|
||||
[POSIXLY_CORRECT](/syntax/shellvars.md#POSIXLY_CORRECT) is set
|
||||
|
||||
### 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`)
|
||||
- starting Bash with the commandline option `--posix`
|
||||
- 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`
|
||||
|
||||
<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
|
||||
|
||||
### 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:
|
||||
|
||||
- the `cd` command can't be used to change directories
|
||||
- the variables [SHELL](/syntax/shellvars#SHELL),
|
||||
[PATH](/syntax/shellvars#PATH), [ENV](/syntax/shellvars#ENV) and
|
||||
[BASH_ENV](/syntax/shellvars#BASH_ENV) can't be set or unset
|
||||
- the variables [SHELL](/syntax/shellvars.md#SHELL),
|
||||
[PATH](/syntax/shellvars.md#PATH), [ENV](/syntax/shellvars.md#ENV) and
|
||||
[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
|
||||
limited to `PATH`)
|
||||
- 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
|
||||
- function definitions are not inherited from the environment at shell
|
||||
startup
|
||||
- the environment variable [SHELLOPTS](/syntax/shellvars#SHELLOPTS) is
|
||||
- the environment variable [SHELLOPTS](/syntax/shellvars.md#SHELLOPTS) is
|
||||
ignored at startup
|
||||
- redirecting output using the `>`, `>|`, `<>`, `>&`, `&>`, and `>>`
|
||||
redirection operators isn't allowed
|
||||
|
@ -19,8 +19,8 @@ Note that the `shopt` builtin command first appeared in Bash 2.0.
|
||||
|
||||
For this topic, see also
|
||||
|
||||
- [shell_options](/internals/shell_options)
|
||||
- [set](/commands/builtin/set)
|
||||
- [shell_options](/internals/shell_options.md)
|
||||
- [set](/commands/builtin/set.md)
|
||||
|
||||
| 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
|
||||
|
||||
- [printf](/commands/builtin/printf)
|
||||
- [printf](/commands/builtin/printf.md)
|
||||
|
||||
| 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
|
||||
|
||||
- [conditional_expression](/syntax/ccmd/conditional_expression)
|
||||
- [classictest](/commands/classictest)
|
||||
- [conditional_expression](/syntax/ccmd/conditional_expression.md)
|
||||
- [classictest](/commands/classictest.md)
|
||||
|
||||
| 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 | |
|
||||
| `select` | new | 1.14.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 | |
|
||||
| `enable` | builtin has basic plugin support (dlopen) | 2.0 | |
|
||||
| `exec` | options `-l`, `-c` and `-a` | 2.0 | |
|
||||
| `read` | options `-p`, `-e` and `-a` | 2.0 | [read](/commands/builtin/read) |
|
||||
| `readonly` | option `-a` | 2.0 | [arrays](/syntax/arrays) |
|
||||
| `read` | options `-p`, `-e` and `-a` | 2.0 | [read](/commands/builtin/read.md) |
|
||||
| `readonly` | option `-a` | 2.0 | [arrays](/syntax/arrays.md) |
|
||||
| `time` | new keyword | 2.0 | |
|
||||
| `shopt` | `-p` (reusable output) | 2.02 | |
|
||||
| `umask` | `-p` (reusable output) | 2.02 | |
|
||||
| `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 |
|
||||
| `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 |
|
||||
| `set` | print shell functions in a format reusable as input | 2.05-beta1 | |
|
||||
| `for` | allow an empty word list | 2.05a-alpha1 | |
|
||||
| `read` | new option `-u` | 2.05b-alpha1 | [read](/commands/builtin/read) |
|
||||
| `caller` | new | 3.0 | [caller](/commands/builtin/caller) |
|
||||
| `read` | new option `-u` | 2.05b-alpha1 | [read](/commands/builtin/read.md) |
|
||||
| `caller` | new | 3.0 | [caller](/commands/builtin/caller.md) |
|
||||
| `coproc` | new | 4.0-alpha | |
|
||||
| `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) |
|
||||
@ -241,7 +241,7 @@ 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 |
|
||||
|:-----------------------------------------------------------------------------------------------------|:-------------------------|:--------------------------------------------------------------------------------------------------------------|
|
||||
@ -282,8 +282,8 @@ For this topic, see also
|
||||
|
||||
For this topic, see also
|
||||
|
||||
- [arith_expr](/syntax/arith_expr)
|
||||
- [arith](/syntax/expansion/arith)
|
||||
- [arith_expr](/syntax/arith_expr.md)
|
||||
- [arith](/syntax/expansion/arith.md)
|
||||
|
||||
| Feature or change description | Appeared in Bash version | Remarks |
|
||||
|:-------------------------------------------|:-------------------------|:------------------------------------------|
|
||||
@ -299,7 +299,7 @@ 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 |
|
||||
|:--------------------------------------------------------------------------------------|:-------------------------|:--------|
|
||||
|
@ -71,7 +71,7 @@ specified by the shebang. \</WRAP\>
|
||||
**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:
|
||||
|
||||
- [Bash behaviour](/scripting/bashbehaviour).
|
||||
- [Bash behaviour](/scripting/bashbehaviour.md).
|
||||
|
||||
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
|
||||
redirection and piping, see:
|
||||
|
||||
- [An illustrated redirection tutorial](/howto/redirection_tutorial)
|
||||
- [An illustrated redirection tutorial](/howto/redirection_tutorial.md)
|
||||
|
||||
## Variable names
|
||||
|
||||
@ -183,7 +183,7 @@ else
|
||||
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.
|
||||
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
|
||||
"commented" text! Check [redirection with
|
||||
here-documents](/syntax/redirection#tag_heredoc) for more
|
||||
here-documents](/syntax/redirection.md#tag_heredoc) for more
|
||||
|
||||
## 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**
|
||||
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
|
||||
in the processtree](/scripting/processtree)!
|
||||
in the processtree](/scripting/processtree.md)!
|
||||
|
||||
### Local variables
|
||||
|
||||
|
@ -55,13 +55,13 @@ Insert **echos** everywhere you can, and print to `stderr`:
|
||||
echo "DEBUG: current i=$i" >&2
|
||||
|
||||
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!
|
||||
|
||||
pid=$(< fooservice.pid)
|
||||
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.
|
||||
|
||||
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
|
||||
input (script file or keyboard)
|
||||
- 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`)
|
||||
- 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
|
||||
`+` (plus) sign to the displayed command)
|
||||
- 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
|
||||
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:
|
||||
|
||||
@ -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
|
||||
|
||||
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
|
||||
foo="bar baz"
|
||||
@ -125,7 +125,7 @@ words (which you would have realized if you READ THE ERROR MESSAGES ;)
|
||||
(by AnMaster)
|
||||
|
||||
`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:
|
||||
|
||||
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
|
||||
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 `if` with a `fi`?
|
||||
@ -230,7 +230,7 @@ command](/syntax/ccmd/intro):
|
||||
**<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
|
||||
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:
|
||||
`` 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
|
||||
- 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
|
||||
|
||||
@ -365,7 +365,7 @@ the possibility that`^M` is involved. Find and eliminate it! |
|
||||
|
||||
## 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
|
||||
|
||||
|
@ -24,8 +24,8 @@ them with <u>Bash</u>, and run them with Bash in <u>native mode</u>.
|
||||
|
||||
See also:
|
||||
|
||||
- [Bash startup mode: SH mode](/scripting/bashbehaviour#sh_mode)
|
||||
- [Bash run mode: POSIX mode](/scripting/bashbehaviour#posix_run_mode)
|
||||
- [Bash startup mode: SH mode](/scripting/bashbehaviour.md#sh_mode)
|
||||
- [Bash run mode: POSIX mode](/scripting/bashbehaviour.md#posix_run_mode)
|
||||
|
||||
### Your script named "test" doesn't execute
|
||||
|
||||
@ -62,7 +62,7 @@ filename expansion happens **after** that, so there is a chance that
|
||||
|
||||
Please see:
|
||||
|
||||
- [brace](/syntax/expansion/brace)
|
||||
- [brace](/syntax/expansion/brace.md)
|
||||
|
||||
## Test-command
|
||||
|
||||
@ -73,7 +73,7 @@ Please see:
|
||||
Please see:
|
||||
|
||||
- [The classic test command -
|
||||
pitfalls](/commands/classictest#pitfalls_summarized)
|
||||
pitfalls](/commands/classictest.md#pitfalls_summarized)
|
||||
|
||||
## Variables
|
||||
|
||||
@ -161,7 +161,7 @@ of the referenced variables/parameters. i.e. **not** (`$PATH`):
|
||||
echo "The first character of PATH is ${PATH:0:1}"
|
||||
|
||||
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. Identical to the previous command.
|
||||
@ -171,10 +171,10 @@ expressions](/syntax/arith_expr), then the bare **name** is allowed:
|
||||
|
||||
Please see:
|
||||
|
||||
- [words](/syntax/words)
|
||||
- [quoting](/syntax/quoting)
|
||||
- [wordsplit](/syntax/expansion/wordsplit)
|
||||
- [pe](/syntax/pe)
|
||||
- [words](/syntax/words.md)
|
||||
- [quoting](/syntax/quoting.md)
|
||||
- [wordsplit](/syntax/expansion/wordsplit.md)
|
||||
- [pe](/syntax/pe.md)
|
||||
|
||||
### Exporting
|
||||
|
||||
@ -204,7 +204,7 @@ In this case, the export command is of no use.
|
||||
|
||||
Please see:
|
||||
|
||||
- [processtree](/scripting/processtree)
|
||||
- [processtree](/scripting/processtree.md)
|
||||
|
||||
## Exit codes
|
||||
|
||||
@ -240,7 +240,7 @@ you need only a "true/false" exit indication, there's no need for `$?`.
|
||||
|
||||
See also:
|
||||
|
||||
- [Exit codes](/scripting/basics#exit_codes)
|
||||
- [Exit codes](/scripting/basics.md#exit_codes)
|
||||
|
||||
### Output vs. Return Value
|
||||
|
||||
@ -274,5 +274,5 @@ Make sure you're using the form you intended:
|
||||
|
||||
Please see:
|
||||
|
||||
- [intro](/syntax/ccmd/intro)
|
||||
- [cmdsubst](/syntax/expansion/cmdsubst)
|
||||
- [intro](/syntax/ccmd/intro.md)
|
||||
- [cmdsubst](/syntax/expansion/cmdsubst.md)
|
||||
|
@ -8,7 +8,7 @@ syntax, with some extensions and derivations.
|
||||
If scripts need to be portable, some of the BASH-specific syntax
|
||||
elements should be avoided. Others should be avoided for all scripts,
|
||||
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.
|
||||
In these cases the portable syntax should be preferred.
|
||||
@ -72,7 +72,7 @@ or<br />
|
||||
<code>test EXPRESSION</code></td>
|
||||
<td style="text-align: center;">The Bashish test keyword is reserved by
|
||||
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>
|
||||
<td style="text-align: center;">POSIX(r) and others</td>
|
||||
</tr>
|
||||
@ -159,7 +159,7 @@ Why? (list of known behaviours)
|
||||
variables or the build options, especially KSH93 and Bash)
|
||||
|
||||
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
|
||||
|
||||
@ -173,7 +173,7 @@ existance of [the `printf` command](/commands/builtin/printf).
|
||||
|
||||
#### 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
|
||||
variable. Workaround to fix the value of `PWD` at the start of your
|
||||
script:
|
||||
@ -182,7 +182,7 @@ script:
|
||||
|
||||
#### 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
|
||||
other available external options, you can use awk to generate a random
|
||||
number. There are multiple implementations of awk and which version your
|
||||
@ -208,12 +208,12 @@ complaining about possible stupid code!*
|
||||
|
||||
#### 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.
|
||||
|
||||
### 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
|
||||
every `PATH` component for the command you're looking for and for
|
||||
executability.
|
||||
|
@ -10,12 +10,12 @@ parameters are described below:
|
||||
|
||||
| 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) |
|
||||
| `$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!) |
|
||||
| `$*` | all positional parameters except `$0`, see [mass usage](/scripting/posparams#mass_usage) |
|
||||
| `$@` | all positional parameters except `$0`, see [mass usage](/scripting/posparams#mass_usage) |
|
||||
| `${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.md#mass_usage) |
|
||||
| `$@` | all positional parameters except `$0`, see [mass usage](/scripting/posparams.md#mass_usage) |
|
||||
| `$#` | the number of arguments, not counting `$0` |
|
||||
|
||||
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
|
||||
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
|
||||
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" ]
|
||||
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
|
||||
(null-string). Let's modify it to run as long as `$1` is defined (but
|
||||
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
|
||||
echo "$1"
|
||||
@ -156,7 +156,7 @@ value](/syntax/pe#use_an_alternate_value):
|
||||
### Getopts
|
||||
|
||||
There is a [small tutorial dedicated to
|
||||
`getopts`](/howto/getopts_tutorial) (*under construction*).
|
||||
`getopts`](/howto/getopts_tutorial.md) (*under construction*).
|
||||
|
||||
## 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
|
||||
is possible for a range of characters using [substring
|
||||
expansion](/syntax/pe#substring_expansion) on normal parameters and the
|
||||
mass expansion range of [arrays](/syntax/arrays).
|
||||
expansion](/syntax/pe.md#substring_expansion) on normal parameters and the
|
||||
mass expansion range of [arrays](/syntax/arrays.md).
|
||||
|
||||
`${@: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 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
|
||||
inside the script or function:
|
||||
|
||||
@ -381,16 +381,16 @@ options" for `ls` and doesn't change anything after it:
|
||||
### Using getopts
|
||||
|
||||
There is a [small tutorial dedicated to
|
||||
`getopts`](/howto/getopts_tutorial) (*under construction*).
|
||||
`getopts`](/howto/getopts_tutorial.md) (*under construction*).
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [getopts_tutorial](/howto/getopts_tutorial)
|
||||
- Internal: [while_loop](/syntax/ccmd/while_loop)
|
||||
- Internal: [c_for](/syntax/ccmd/c_for)
|
||||
- Internal: [arrays](/syntax/arrays) (for equivalent syntax for
|
||||
- Internal: [getopts_tutorial](/howto/getopts_tutorial.md)
|
||||
- Internal: [while_loop](/syntax/ccmd/while_loop.md)
|
||||
- Internal: [c_for](/syntax/ccmd/c_for.md)
|
||||
- Internal: [arrays](/syntax/arrays.md) (for equivalent syntax for
|
||||
mass-expansion)
|
||||
- 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)
|
||||
- Dictionary, internal: [parameter](/dict/terms/parameter)
|
||||
|
@ -25,8 +25,8 @@ into the environment with the bash builtin command `export`:
|
||||
|
||||
export MYVAR
|
||||
|
||||
Common system variables like [PATH](/syntax/shellvars#PATH) or
|
||||
[HOME](/syntax/shellvars#HOME) are usually part of the environment (as
|
||||
Common system variables like [PATH](/syntax/shellvars.md#PATH) or
|
||||
[HOME](/syntax/shellvars.md#HOME) are usually part of the environment (as
|
||||
set by login scripts or programs).
|
||||
|
||||
## Executing programs
|
||||
@ -161,7 +161,7 @@ are run inside a subshell:
|
||||
|
||||
### 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
|
||||
set a variable. The other command is run in a subshell:
|
||||
|
||||
|
@ -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
|
||||
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
|
||||
|
||||
@ -55,7 +55,7 @@ supports the visual impression of "these belong together".
|
||||
|
||||
### 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
|
||||
they contain a kind of "head" and a "body" that contains command lists.
|
||||
This type of compound command is relatively easy to indent.
|
||||
@ -241,7 +241,7 @@ Bash, but is not a good idea.
|
||||
### Command substitution
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
`function` keyword (here using the [grouping compound
|
||||
command](/syntax/ccmd/grouping_plain)):
|
||||
command](/syntax/ccmd/grouping_plain.md)):
|
||||
|
||||
getargs() {
|
||||
...
|
||||
|
@ -225,27 +225,27 @@ Some stuff I didn't like there:
|
||||
|
||||
- uses external, unreliable command `which` instead of builtin `type -p`
|
||||
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
|
||||
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
|
||||
substitution](/syntax/expansion/cmdsubst)
|
||||
substitution](/syntax/expansion/cmdsubst.md)
|
||||
- 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
|
||||
- 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
|
||||
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 only thing Bash can execute and check
|
||||
- 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
|
||||
"old way" with `test`, not [modern arithmetic
|
||||
components](/syntax/arith_expr)
|
||||
- useless [quoting](/syntax/quoting) of one-word strings (not that it
|
||||
components](/syntax/arith_expr.md)
|
||||
- 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
|
||||
quotes)
|
||||
- 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** ;-) ):
|
||||
|
||||
- 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)
|
||||
|
||||
\<BOOKMARK:rv_bprogintrohowto\>
|
||||
@ -288,14 +288,14 @@ A few points:
|
||||
|
||||
- uses `function SOMENAME` instead of more common and most portable
|
||||
`SOMENAME()` to [define
|
||||
functions](/syntax/basicgrammar#shell_function_definitions)
|
||||
- wrong description of the [if clause](/syntax/ccmd/if_clause) (says
|
||||
functions](/syntax/basicgrammar.md#shell_function_definitions)
|
||||
- wrong description of the [if clause](/syntax/ccmd/if_clause.md) (says
|
||||
"the base \[...\] is `if [expression];`", which is wrong)
|
||||
- a [for-loop example](/syntax/ccmd/classic_for) will explode due to
|
||||
[word splitting](/syntax/expansion/wordsplit) (`for i in $( ls )` -
|
||||
- a [for-loop example](/syntax/ccmd/classic_for.md) will explode due to
|
||||
[word splitting](/syntax/expansion/wordsplit.md) (`for i in $( ls )` -
|
||||
evil!)
|
||||
- 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
|
||||
|
||||
I like the style this article is written in. If the points are fixed, it
|
||||
|
@ -12,7 +12,7 @@ tutorial.
|
||||
|
||||
## List of snippets
|
||||
|
||||
[reset filter](/snipplets/start)
|
||||
[reset filter](/snipplets/start.md)
|
||||
|
||||
---- datacloud snippet ---- field: snipplet_tags
|
||||
|
||||
|
142
start.md
142
start.md
@ -32,88 +32,88 @@ only there to prevent SPAM.
|
||||
|
||||
- [Bash v4 - a rough overview](bash4.md) (unmaintained, since Bash 4 is
|
||||
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
|
||||
- [basics](/scripting/basics.md)
|
||||
- [newbie_traps](/scripting/newbie_traps.md)
|
||||
- [bashbehaviour](/scripting/bashbehaviour.md)
|
||||
- [posparams](/scripting/posparams.md)
|
||||
- [processtree](/scripting/processtree.md)
|
||||
- [obsolete](/scripting/obsolete.md)
|
||||
- [nonportable](/scripting/nonportable.md)
|
||||
- [debuggingtips](/scripting/debuggingtips.md)
|
||||
- [terminalcodes](/scripting/terminalcodes.md)
|
||||
- [tutoriallist](/scripting/tutoriallist.md)
|
||||
- [basics](/scripting/basics.md.md)
|
||||
- [newbie_traps](/scripting/newbie_traps.md.md)
|
||||
- [bashbehaviour](/scripting/bashbehaviour.md.md)
|
||||
- [posparams](/scripting/posparams.md.md)
|
||||
- [processtree](/scripting/processtree.md.md)
|
||||
- [obsolete](/scripting/obsolete.md.md)
|
||||
- [nonportable](/scripting/nonportable.md.md)
|
||||
- [debuggingtips](/scripting/debuggingtips.md.md)
|
||||
- [terminalcodes](/scripting/terminalcodes.md.md)
|
||||
- [tutoriallist](/scripting/tutoriallist.md.md)
|
||||
|
||||
## 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
|
||||
|
||||
[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)
|
||||
- [Rudimentary config files for your scripts](/howto/conffile.md)
|
||||
- [Editing files with ed(1)](/howto/edit-ed.md)
|
||||
- [Collapsing Functions](/howto/collapsing_functions.md)
|
||||
- [Illustrated Redirection Tutorial](/howto/redirection_tutorial.md)
|
||||
- [Simple locking (against parallel run)](/howto/mutex.md.md)
|
||||
- [Rudimentary config files for your scripts](/howto/conffile.md.md)
|
||||
- [Editing files with ed(1)](/howto/edit-ed.md.md)
|
||||
- [Collapsing Functions](/howto/collapsing_functions.md.md)
|
||||
- [Illustrated Redirection Tutorial](/howto/redirection_tutorial.md.md)
|
||||
- [Calculate with dc(1)](/howto/calculate-dc.md)
|
||||
- [Introduction to pax - the POSIX archiver](/howto/pax.md)
|
||||
- [getopts_tutorial](/howto/getopts_tutorial.md) (*under construction!*)
|
||||
- [dissectabadoneliner](/howto/dissectabadoneliner.md) An example of a bad
|
||||
- [Introduction to pax - the POSIX archiver](/howto/pax.md.md)
|
||||
- [getopts_tutorial](/howto/getopts_tutorial.md.md) (*under construction!*)
|
||||
- [dissectabadoneliner](/howto/dissectabadoneliner.md.md) An example of a bad
|
||||
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
|
||||
|
||||
## Bash syntax and operations
|
||||
|
||||
- [Bash features overview by version](/scripting/bashchanges.md)
|
||||
- [Basic grammar rules](/syntax/basicgrammar.md)
|
||||
- [Quoting and character escaping](/syntax/quoting.md)
|
||||
- [Parsing and execution](/syntax/grammar/parser_exec.md)
|
||||
- [Some words about words...](/syntax/words.md)
|
||||
- [Patterns and pattern matching](/syntax/pattern.md)
|
||||
- [Arithmetic expressions](/syntax/arith_expr.md)
|
||||
- [List of shell options](/internals/shell_options.md)
|
||||
- [Redirection](/syntax/redirection.md)
|
||||
- [Special parameters and shell variables](/syntax/shellvars.md)
|
||||
- [Arrays](/syntax/arrays.md)
|
||||
- [Bash features overview by version](/scripting/bashchanges.md.md)
|
||||
- [Basic grammar rules](/syntax/basicgrammar.md.md)
|
||||
- [Quoting and character escaping](/syntax/quoting.md.md)
|
||||
- [Parsing and execution](/syntax/grammar/parser_exec.md.md)
|
||||
- [Some words about words...](/syntax/words.md.md)
|
||||
- [Patterns and pattern matching](/syntax/pattern.md.md)
|
||||
- [Arithmetic expressions](/syntax/arith_expr.md.md)
|
||||
- [List of shell options](/internals/shell_options.md.md)
|
||||
- [Redirection](/syntax/redirection.md.md)
|
||||
- [Special parameters and shell variables](/syntax/shellvars.md.md)
|
||||
- [Arrays](/syntax/arrays.md.md)
|
||||
|
||||
## Compound commands
|
||||
|
||||
| **[Compound commands overview](/syntax/ccmd/intro.md)** | |
|
||||
| **[Compound commands overview](/syntax/ccmd/intro.md.md)** | |
|
||||
|:-----------------------------------------------------|------------------------------------------------------------------|
|
||||
| Grouping | |
|
||||
| `{ ...; }` | [command grouping](/syntax/ccmd/grouping_plain.md) |
|
||||
| `( ... )` | [command grouping in a subshell](/syntax/ccmd/grouping_subshell.md) |
|
||||
| `{ ...; }` | [command grouping](/syntax/ccmd/grouping_plain.md.md) |
|
||||
| `( ... )` | [command grouping in a subshell](/syntax/ccmd/grouping_subshell.md.md) |
|
||||
| Conditionals | |
|
||||
| `[[ ... ]]` | [conditional expression](/syntax/ccmd/conditional_expression.md) |
|
||||
| `if ...; then ...; fi` | [conditional branching](/syntax/ccmd/if_clause.md) |
|
||||
| `case ... esac` | [pattern-based branching](/syntax/ccmd/case.md) |
|
||||
| `[[ ... ]]` | [conditional expression](/syntax/ccmd/conditional_expression.md.md) |
|
||||
| `if ...; then ...; fi` | [conditional branching](/syntax/ccmd/if_clause.md.md) |
|
||||
| `case ... esac` | [pattern-based branching](/syntax/ccmd/case.md.md) |
|
||||
| Loops | |
|
||||
| `for word in ...; do ...; done` | [classic for-loop](/syntax/ccmd/classic_for.md) |
|
||||
| `for ((x=1; x<=10; x++)); do ...; done` | [C-style for-loop](/syntax/ccmd/c_for.md) |
|
||||
| `while ...; do ...; done` | [while loop](/syntax/ccmd/while_loop.md) |
|
||||
| `until ...; do ...; done` | [until loop](/syntax/ccmd/until_loop.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.md) |
|
||||
| `while ...; do ...; done` | [while loop](/syntax/ccmd/while_loop.md.md) |
|
||||
| `until ...; do ...; done` | [until loop](/syntax/ccmd/until_loop.md.md) |
|
||||
| Misc | |
|
||||
| `(( ... ))` | [arithmetic evaluation](/syntax/ccmd/arithmetic_eval.md) |
|
||||
| `select word in ...; do ...; done` | [user selections](/syntax/ccmd/user_select.md) |
|
||||
| `(( ... ))` | [arithmetic evaluation](/syntax/ccmd/arithmetic_eval.md.md) |
|
||||
| `select word in ...; do ...; done` | [user selections](/syntax/ccmd/user_select.md.md) |
|
||||
|
||||
## 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) |
|
||||
| `~/ ~root/` | [Tilde expansion](/syntax/expansion/tilde.md) |
|
||||
| `$FOO ${BAR%.mp3}` | [Parameter expansion](/syntax/pe.md) |
|
||||
| `` `command` $(command) `` | [Command substitution](/syntax/expansion/cmdsubst.md) |
|
||||
| `<(command) >(command)` | [Process substitution](/syntax/expansion/proc_subst.md) |
|
||||
| `$((1 + 2 + 3)) $[4 + 5 + 6]` | [Arithmetic expansion](/syntax/expansion/arith.md) |
|
||||
| `Hello <---> Word!` | [Word splitting](/syntax/expansion/wordsplit.md) |
|
||||
| `/data/*-av/*.mp?` | [Pathname expansion](/syntax/expansion/globs.md) |
|
||||
| `{A,B,C} {A..C}` | [Brace expansion](/syntax/expansion/brace.md.md) |
|
||||
| `~/ ~root/` | [Tilde expansion](/syntax/expansion/tilde.md.md) |
|
||||
| `$FOO ${BAR%.mp3}` | [Parameter expansion](/syntax/pe.md.md) |
|
||||
| `` `command` $(command) `` | [Command substitution](/syntax/expansion/cmdsubst.md.md) |
|
||||
| `<(command) >(command)` | [Process substitution](/syntax/expansion/proc_subst.md.md) |
|
||||
| `$((1 + 2 + 3)) $[4 + 5 + 6]` | [Arithmetic expansion](/syntax/expansion/arith.md.md) |
|
||||
| `Hello <---> Word!` | [Word splitting](/syntax/expansion/wordsplit.md.md) |
|
||||
| `/data/*-av/*.mp?` | [Pathname expansion](/syntax/expansion/globs.md.md) |
|
||||
|
||||
|
||||
## Builtin Commands
|
||||
@ -137,7 +137,7 @@ datastructures.</th>
|
||||
<tbody>
|
||||
<tr class="odd">
|
||||
<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
|
||||
attributes.</td>
|
||||
<td style="text-align: center;"><code>typeset</code></td>
|
||||
@ -167,14 +167,14 @@ href="/commands/builtin/local">local</a></td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;"><code>typeset -r</code></td>
|
||||
<td style="text-align: center;">special builtin</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<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 style="text-align: center;">-</td>
|
||||
<td style="text-align: center;">special builtin</td>
|
||||
@ -197,7 +197,7 @@ streams.</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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
|
||||
/ writing its standard streams.</td>
|
||||
<td style="text-align: center;">-</td>
|
||||
@ -212,21 +212,21 @@ href="/commands/builtin/echo">echo</a></td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;"><code>readarray</code></td>
|
||||
<td style="text-align: center;">builtin</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<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 style="text-align: center;">-</td>
|
||||
<td style="text-align: center;">builtin</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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
|
||||
using delimiters.</td>
|
||||
<td style="text-align: center;">-</td>
|
||||
@ -241,14 +241,14 @@ Commands that modify shell behavior, change special options, assist in debugging
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;">-</td>
|
||||
<td style="text-align: center;">builtin</td>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<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
|
||||
behaviour.</td>
|
||||
<td style="text-align: center;">-</td>
|
||||
@ -256,7 +256,7 @@ behaviour.</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;">-</td>
|
||||
<td style="text-align: center;">builtin</td>
|
||||
@ -305,7 +305,7 @@ href="/commands/builtin/continueBreak">continue / break</a></td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;">-</td>
|
||||
<td style="text-align: center;">builtin</td>
|
||||
@ -319,7 +319,7 @@ href="/commands/builtin/return">return</a></td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;">test</td>
|
||||
<td style="text-align: center;">builtin</td>
|
||||
@ -334,7 +334,7 @@ signals, process groups, subshells.</td>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<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 style="text-align: center;">-</td>
|
||||
<td style="text-align: center;">special builtin</td>
|
||||
@ -385,7 +385,7 @@ href="/commands/builtin/wait">wait</a></td>
|
||||
|
||||
## 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
|
||||
@ -474,7 +474,7 @@ href="/commands/builtin/wait">wait</a></td>
|
||||
commands](https://www.rosehosting.com/blog/basic-shell-commands-after-putty-ssh-logon/)
|
||||
- [Bashphorism list from the Bash IRC channel on
|
||||
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
|
||||
Tutorial](https://thishosting.rocks/how-to-enable-ssh-on-ubuntu/)
|
||||
- [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
|
||||
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, ...)!
|
||||
|
||||
It also would be nice to drop a line when
|
||||
|
@ -4,13 +4,13 @@
|
||||
|
||||
Arithmetic expressions are used in several situations:
|
||||
|
||||
- [arithmetic evaluation command](/syntax/ccmd/arithmetic_eval)
|
||||
- [arithmetic expansion](/syntax/expansion/arith)
|
||||
- [substring parameter expansion](/syntax/pe#substring_expansion)
|
||||
- [the `let` builtin command](/commands/builtin/let)
|
||||
- [C-style for loop](/syntax/ccmd/c_for)
|
||||
- [array indexing](/syntax/arrays)
|
||||
- [conditional expressions](/syntax/ccmd/conditional_expression)
|
||||
- [arithmetic evaluation command](/syntax/ccmd/arithmetic_eval.md)
|
||||
- [arithmetic expansion](/syntax/expansion/arith.md)
|
||||
- [substring parameter expansion](/syntax/pe.md#substring_expansion)
|
||||
- [the `let` builtin command](/commands/builtin/let.md)
|
||||
- [C-style for loop](/syntax/ccmd/c_for.md)
|
||||
- [array indexing](/syntax/arrays.md)
|
||||
- [conditional expressions](/syntax/ccmd/conditional_expression.md)
|
||||
- Assignment statements, and arguments to declaration commands of
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
## Shell variables
|
||||
@ -121,7 +121,7 @@ When variables are referenced, the notation `1 + $X` is equivalent to
|
||||
the notation `1 + X`, both are allowed.
|
||||
|
||||
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
|
||||
an arithmetic expression.
|
||||
|
||||
@ -130,7 +130,7 @@ an arithmetic expression.
|
||||
Unlike command exit and return codes, arithmetic expressions evaluate to
|
||||
logical "true" when they are not 0. When they are 0, they evaluate to
|
||||
"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:
|
||||
|
||||
- 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 |
|
||||
|---------------------|----------------------------------------------------------------------------------------------------|
|
||||
| `<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#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#calculations) |
|
||||
| `<ID> -= <EXPR>` | equivalent to `<ID> = <ID> - <EXPR>`, see [calculation operators](/syntax/arith_expr#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#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#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 [calculation operators](/syntax/arith_expr.md#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.md#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.md#calculations) |
|
||||
| `<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.md#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.md#bit_operations) |
|
||||
| `<ID> |= <EXPR>` | equivalent to `<ID> = <ID> | <EXPR>`, see [bit operations](/syntax/arith_expr.md#bit_operations) |
|
||||
|
||||
### Calculations
|
||||
|
||||
@ -368,7 +368,7 @@ under set -e. \</WRAP\>
|
||||
|
||||
## Arithmetic expressions in Bash
|
||||
|
||||
- [The C-style for-loop](/syntax/ccmd/c_for)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith)
|
||||
- [Arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval)
|
||||
- [The "let" builtin command](/commands/builtin/let)
|
||||
- [The C-style for-loop](/syntax/ccmd/c_for.md)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith.md)
|
||||
- [Arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval.md)
|
||||
- [The "let" builtin command](/commands/builtin/let.md)
|
||||
|
@ -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
|
||||
are **always sparse**, meaning indexes are not necessarily contiguous.
|
||||
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
|
||||
numerical array indexes start at 0 (zero). Indexed arrays are the most
|
||||
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
|
||||
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
|
||||
a Bash parameter that has been given the `-a` (for indexed) or `-A` (for
|
||||
associative) *attributes*. However, any regular (non-special or
|
||||
@ -116,7 +116,7 @@ variables.
|
||||
|
||||
| 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=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. |
|
||||
@ -130,7 +130,7 @@ As of now, arrays can't be exported.
|
||||
### Getting values
|
||||
|
||||
| :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. |
|
||||
| --- |
|
||||
|
||||
@ -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[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[@]: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[@]}" ${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.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
|
||||
mass-expanding, then the behaviour is exactly what it is for `$@` and
|
||||
`$*` 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.
|
||||
|
||||
### Metadata
|
||||
@ -220,7 +220,7 @@ variables with unset.
|
||||
|
||||
| :warning: Specifying unquoted array elements as arguments to any
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
- [Parameter expansion](/syntax/pe) (contains sections for arrays)
|
||||
- [classic_for](/syntax/ccmd/classic_for) (contains some examples to
|
||||
- [Parameter expansion](/syntax/pe.md) (contains sections for arrays)
|
||||
- [classic_for](/syntax/ccmd/classic_for.md) (contains some examples to
|
||||
iterate over arrays)
|
||||
- [declare](/commands/builtin/declare)
|
||||
- [declare](/commands/builtin/declare.md)
|
||||
- [BashFAQ 005 - How can I use array
|
||||
variables?](http://mywiki.wooledge.org/BashFAQ/005) - A very detailed
|
||||
discussion on arrays with many examples.
|
||||
|
@ -42,7 +42,7 @@ issue to report back to the calling program.
|
||||
**base** for all higher constructs. Everything you execute, from
|
||||
pipelines to functions, finally ends up in (many) simple commands.
|
||||
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
|
||||
|
||||
@ -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
|
||||
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
|
||||
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
|
||||
@ -131,7 +131,7 @@ Your whole Bash script technically is one big single list!
|
||||
|
||||
## 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:
|
||||
|
||||
@ -150,17 +150,17 @@ overview):
|
||||
|
||||
| Compound command syntax | Description |
|
||||
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `( <LIST> )` | Execute `<LIST>` in an extra subshell =\> [article](/syntax/ccmd/grouping_subshell) |
|
||||
| `{ <LIST> ; }` | Execute `<LIST>` as separate group (but not in a subshell) =\> [article](/syntax/ccmd/grouping_plain) |
|
||||
| `(( <EXPRESSION> ))` | Evaluate the arithmetic expression `<EXPRESSION>` =\> [article](/syntax/ccmd/arithmetic_eval) |
|
||||
| `[[ <EXPRESSION> ]]` | Evaluate the conditional expression `<EXPRESSION>` (aka "the new test command") =\> [article](/syntax/ccmd/conditional_expression) |
|
||||
| `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 (( <EXPR1> ; <EXPR2> ; <EXPR3> )) ; do <LIST> ; done` | C-style for-loop (driven by arithmetic expressions) =\> [article](/syntax/ccmd/c_for) |
|
||||
| `select <NAME> in <WORDS> ; do <LIST> ; done` | Provides simple menus =\> [article](/syntax/ccmd/user_select) |
|
||||
| `case <WORD> in <PATTERN>) <LIST> ;; ... esac` | Decisions based on pattern matching - executing `<LIST>` on match =\> [article](/syntax/ccmd/case) |
|
||||
| `if <LIST> ; then <LIST> ; else <LIST> ; fi` | The if clause: makes decisions based on exit codes =\> [article](/syntax/ccmd/if_clause) |
|
||||
| `while <LIST1> ; do <LIST2> ; done` | Execute `<LIST2>` while `<LIST1>` returns TRUE (exit code) =\> [article](/syntax/ccmd/while_loop) |
|
||||
| `until <LIST1> ; do <LIST2> ; done` | Execute `<LIST2>` until `<LIST1>` returns TRUE (exit code) =\> [article](/syntax/ccmd/until_loop) |
|
||||
| `( <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.md) |
|
||||
| `(( <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.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.md) |
|
||||
| `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.md) |
|
||||
| `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.md) |
|
||||
| `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.md) |
|
||||
|
||||
## Shell Function Definitions
|
||||
|
||||
@ -320,10 +320,10 @@ Let's invert test command exit code, only one thing changes:
|
||||
|
||||
## 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
|
||||
commands](/syntax/grammar/parser_exec)
|
||||
- Internal: [Quoting and escaping](/syntax/quoting)
|
||||
commands](/syntax/grammar/parser_exec.md)
|
||||
- Internal: [Quoting and escaping](/syntax/quoting.md)
|
||||
- Internal: [Introduction to expansions and
|
||||
substitutions](/syntax/expansion/intro)
|
||||
- Internal: [Some words about words...](/syntax/words)
|
||||
substitutions](/syntax/expansion/intro.md)
|
||||
- Internal: [Some words about words...](/syntax/words.md)
|
||||
|
@ -6,17 +6,17 @@
|
||||
|
||||
## Description
|
||||
|
||||
This command evaluates the [arithmetic expression](/syntax/arith_expr)
|
||||
This command evaluates the [arithmetic expression](/syntax/arith_expr.md)
|
||||
`<EXPRESSION>`.
|
||||
|
||||
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
|
||||
0, then the exit code of the expression is set to 0 (`TRUE`). 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).
|
||||
|
||||
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.
|
||||
|
||||
## Examples
|
||||
@ -25,6 +25,6 @@ command should be preferred.
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [arithmetic expressions](/syntax/arith_expr)
|
||||
- Internal: [arithmetic expansion](/syntax/expansion/arith)
|
||||
- Internal: [The `let` builtin command](/commands/builtin/let)
|
||||
- Internal: [arithmetic expressions](/syntax/arith_expr.md)
|
||||
- Internal: [arithmetic expansion](/syntax/expansion/arith.md)
|
||||
- Internal: [The `let` builtin command](/commands/builtin/let.md)
|
||||
|
@ -29,7 +29,7 @@ mechanisms available in the language.
|
||||
The `((;;))` syntax at the top of the loop is not an ordinary
|
||||
[arithmetic compound command](syntax/ccmd/arithmetic_eval), but is part
|
||||
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
|
||||
processed for: brace, parameter, command, arithmetic, and process
|
||||
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)
|
||||
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> ))
|
||||
while (( <EXPR2> )); do
|
||||
@ -135,7 +135,7 @@ ending at 1. If that bit is set in the `testbyte`, it prints "`1`", else
|
||||
bits).
|
||||
|
||||
#!/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.
|
||||
|
||||
function toBin {
|
||||
@ -231,6 +231,6 @@ variables.
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [Arithmetic expressions](/syntax/arith_expr)
|
||||
- Internal: [The classic for-loop](/syntax/ccmd/classic_for)
|
||||
- Internal: [The while-loop](/syntax/ccmd/while_loop)
|
||||
- Internal: [Arithmetic expressions](/syntax/arith_expr.md)
|
||||
- Internal: [The classic for-loop](/syntax/ccmd/classic_for.md)
|
||||
- Internal: [The while-loop](/syntax/ccmd/while_loop.md)
|
||||
|
@ -13,9 +13,9 @@
|
||||
## Description
|
||||
|
||||
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
|
||||
[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
|
||||
last commandlist (i.e., you can omit the `;;` before the `esac`). Every
|
||||
`<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
|
||||
|
||||
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).
|
||||
|
||||
Unlike the C-case-statement, only the matching list and nothing else is
|
||||
|
@ -66,7 +66,7 @@ empty"!).
|
||||
|
||||
### 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
|
||||
mass-expanding all elements):
|
||||
|
||||
@ -88,7 +88,7 @@ done
|
||||
### List positional parameters
|
||||
|
||||
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:
|
||||
|
||||
``` bash
|
||||
@ -138,7 +138,7 @@ done
|
||||
This is just an example. In *general*
|
||||
|
||||
- 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
|
||||
|
||||
### Nested for-loops
|
||||
@ -157,7 +157,7 @@ done
|
||||
### Loop over a number range
|
||||
|
||||
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
|
||||
them:
|
||||
|
||||
|
@ -10,14 +10,14 @@
|
||||
|
||||
## 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
|
||||
**newline** or **semicolon**. For parsing reasons, the curly braces must
|
||||
be separated from `<LIST>` by a **semicolon** and **blanks** if they're
|
||||
in the same line! [^1][^2]
|
||||
|
||||
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:
|
||||
|
||||
@ -30,7 +30,7 @@ The input and output **filedescriptors** are cumulative:
|
||||
} >output.txt
|
||||
|
||||
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:
|
||||
|
||||
print_help() {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
## 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
|
||||
etc...) are reflected in the "main shell".
|
||||
|
||||
@ -31,5 +31,5 @@ echo "$PWD" # Still in the original directory.
|
||||
|
||||
## 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)
|
||||
|
@ -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.
|
||||
|
||||
All commandsets `<LIST>` are interpreted as [command
|
||||
lists](/syntax/basicgrammar#lists), thus they can contain the whole
|
||||
palette from [simple commands](/syntax/basicgrammar#simple_commands)
|
||||
over [pipelines](/syntax/basicgrammar#pipelines) to [compound
|
||||
commands](/syntax/basicgrammar#compound_commands) (and their
|
||||
lists](/syntax/basicgrammar.md#lists), thus they can contain the whole
|
||||
palette from [simple commands](/syntax/basicgrammar.md#simple_commands)
|
||||
over [pipelines](/syntax/basicgrammar.md#pipelines) to [compound
|
||||
commands](/syntax/basicgrammar.md#compound_commands) (and their
|
||||
combination) as condition.
|
||||
|
||||
### Operation
|
||||
@ -88,4 +88,4 @@ example above (multiple commands):
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [the classic test command](/commands/classictest)
|
||||
- Internal: [the classic test command](/commands/classictest.md)
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
The main part of Bash's syntax are the so-called **compound commands**.
|
||||
They're called like that because they use "real" commands ([simple
|
||||
commands](/syntax/basicgrammar#simple_commands) or
|
||||
[lists](/syntax/basicgrammar#lists)) and knit some intelligence around
|
||||
commands](/syntax/basicgrammar.md#simple_commands) or
|
||||
[lists](/syntax/basicgrammar.md#lists)) and knit some intelligence around
|
||||
them. That is what the essential "Bash language" is made of.
|
||||
|
||||
## Command grouping
|
||||
@ -14,7 +14,7 @@ them. That is what the essential "Bash language" is made of.
|
||||
## Conditional reactions
|
||||
|
||||
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.
|
||||
|
||||
- the "new" test command: [conditional
|
||||
|
@ -9,12 +9,12 @@
|
||||
## Description
|
||||
|
||||
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
|
||||
again and again until `<LIST1>` returns TRUE.
|
||||
|
||||
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
|
||||
can be
|
||||
@ -35,4 +35,4 @@ or `0` (`TRUE`) if none was executed.
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [The while loop](/syntax/ccmd/while_loop)
|
||||
- Internal: [The while loop](/syntax/ccmd/while_loop.md)
|
||||
|
@ -27,7 +27,7 @@
|
||||
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
|
||||
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.
|
||||
|
||||
If no `in <WORDS>` is given, then the positional parameters are taken as
|
||||
|
@ -9,12 +9,12 @@
|
||||
## Description
|
||||
|
||||
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
|
||||
again until `<LIST1>` returns FALSE.
|
||||
|
||||
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
|
||||
can be
|
||||
@ -35,7 +35,7 @@ or `0` (`TRUE`) if none was executed.
|
||||
|
||||
## 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
|
||||
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
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
$[ <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
|
||||
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
|
||||
for the boolean value of an arithmetic expression. This can be done
|
||||
using the [arithmetic evaluation compound
|
||||
command](/syntax/ccmd/arithmetic_eval):
|
||||
command](/syntax/ccmd/arithmetic_eval.md):
|
||||
|
||||
``` bash
|
||||
printf %s 'Enter a number: ' >&2
|
||||
@ -66,8 +66,8 @@ echo $(($x[0])) # Error. This expands to $((1[0])), an invalid expression.
|
||||
|
||||
## See also
|
||||
|
||||
- [arithmetic expressions](/syntax/arith_expr)
|
||||
- [arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval)
|
||||
- [Introduction to expansion and substitution](/syntax/expansion/intro)
|
||||
- [arithmetic expressions](/syntax/arith_expr.md)
|
||||
- [arithmetic evaluation compound command](/syntax/ccmd/arithmetic_eval.md)
|
||||
- [Introduction to expansion and substitution](/syntax/expansion/intro.md)
|
||||
- [POSIX
|
||||
definition](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04)
|
||||
|
@ -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
|
||||
expansions. If the sequence expansion is to be assigned to an array,
|
||||
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`
|
||||
This is significantly safer, but one must still be careful to control
|
||||
the values of \$a and \$b. Both the exact quoting, and explicitly
|
||||
|
@ -14,8 +14,8 @@ All **trailing** newlines are removed (below is an example for a
|
||||
workaround).
|
||||
|
||||
In later steps, **if not quoted**, the results undergo [word
|
||||
splitting](/syntax/expansion/wordsplit) and [pathname
|
||||
expansion](/syntax/expansion/globs). You have to remember that, because
|
||||
splitting](/syntax/expansion/wordsplit.md) and [pathname
|
||||
expansion](/syntax/expansion/globs.md). You have to remember that, because
|
||||
the word splitting will also remove embedded newlines and other `IFS`
|
||||
characters and break the results up into several words. Also you'll
|
||||
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)
|
||||
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
|
||||
way is **wrong**:
|
||||
|
||||
$((COMMAND))
|
||||
|
||||
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)`:
|
||||
|
||||
$( (COMMAND) )
|
||||
@ -133,5 +133,5 @@ output with its trailing newlines.
|
||||
## See also
|
||||
|
||||
- Internal: [Introduction to expansion and
|
||||
substitution](/syntax/expansion/intro)
|
||||
- Internal: [Obsolete and deprecated syntax](/scripting/obsolete)
|
||||
substitution](/syntax/expansion/intro.md)
|
||||
- Internal: [Obsolete and deprecated syntax](/scripting/obsolete.md)
|
||||
|
@ -11,16 +11,16 @@ expanded filenames as its arguments (here, all filenames matching
|
||||
grep "changes:" *.log
|
||||
|
||||
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.
|
||||
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
|
||||
other `IFS`-characters they contain.
|
||||
|
||||
## 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
|
||||
- when matching a pathname, the slash-character (`/`) always needs to be
|
||||
matched explicitly
|
||||
@ -49,7 +49,7 @@ other `IFS`-characters they contain.
|
||||
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...`) -
|
||||
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
|
||||
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).
|
||||
|
||||
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
|
||||
echo "=== BEGIN: $filename ==="
|
||||
@ -106,8 +106,8 @@ followed by two numbers, followed by at least 3 more characters:
|
||||
|
||||
## See also
|
||||
|
||||
- [Introduction to expansion and substitution](/syntax/expansion/intro)
|
||||
- [pattern matching syntax](/syntax/pattern)
|
||||
- [the set builtin command](/commands/builtin/set)
|
||||
- [the shopt builtin command](/commands/builtin/shopt)
|
||||
- [list of shell options](/internals/shell_options)
|
||||
- [Introduction to expansion and substitution](/syntax/expansion/intro.md)
|
||||
- [pattern matching syntax](/syntax/pattern.md)
|
||||
- [the set builtin command](/commands/builtin/set.md)
|
||||
- [the shopt builtin command](/commands/builtin/shopt.md)
|
||||
- [list of shell options](/internals/shell_options.md)
|
||||
|
@ -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
|
||||
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
|
||||
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
|
||||
small list.
|
||||
|
||||
- [Parameter expansion](/syntax/pe) (it has its own [overview
|
||||
section](/syntax/pe#overview))
|
||||
- [Parameter expansion](/syntax/pe.md) (it has its own [overview
|
||||
section](/syntax/pe.md#overview))
|
||||
- `$WORD`
|
||||
- `${STUFF...}`
|
||||
- [Pathname expansion](/syntax/expansion/globs)
|
||||
- [Pathname expansion](/syntax/expansion/globs.md)
|
||||
- `*.txt`
|
||||
- `page_1?.html`
|
||||
- [Arithmetic expansion](/syntax/expansion/arith)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith.md)
|
||||
- `$(( EXPRESSION ))`
|
||||
- `$[ EXPRESSION ]`
|
||||
- [Command substitution](/syntax/expansion/cmdsubst)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst.md)
|
||||
- `$( 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}`
|
||||
- `{X..Y..Z}`
|
||||
- [Process substitution](/syntax/expansion/proc_subst)
|
||||
- [Process substitution](/syntax/expansion/proc_subst.md)
|
||||
- `<( COMMAND )`
|
||||
- `>( COMMAND )`
|
||||
|
||||
@ -64,25 +64,25 @@ splitting!).
|
||||
|
||||
The order is (from first to last):
|
||||
|
||||
- [Brace expansion](/syntax/expansion/brace)
|
||||
- [Tilde expansion](/syntax/expansion/tilde)
|
||||
- [Brace expansion](/syntax/expansion/brace.md)
|
||||
- [Tilde expansion](/syntax/expansion/tilde.md)
|
||||
- The following expansions happen at the same time, in a left-to-right
|
||||
fashion on the commandline (see below)
|
||||
- [Parameter expansion](/syntax/pe)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst)
|
||||
- [Word splitting](/syntax/expansion/wordsplit)
|
||||
- [Pathname expansion](/syntax/expansion/globs)
|
||||
- [Parameter expansion](/syntax/pe.md)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith.md)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst.md)
|
||||
- [Word splitting](/syntax/expansion/wordsplit.md)
|
||||
- [Pathname expansion](/syntax/expansion/globs.md)
|
||||
|
||||
[Process substitution](/syntax/expansion/proc_subst) is performed
|
||||
**simultaneously** with [parameter expansion](/syntax/pe), [command
|
||||
substitution](/syntax/expansion/cmdsubst) and [arithmetic
|
||||
expansion](/syntax/expansion/arith). It is only performed when the
|
||||
[Process substitution](/syntax/expansion/proc_subst.md) is performed
|
||||
**simultaneously** with [parameter expansion](/syntax/pe.md), [command
|
||||
substitution](/syntax/expansion/cmdsubst.md) and [arithmetic
|
||||
expansion](/syntax/expansion/arith.md). It is only performed when the
|
||||
underlying operating system supports it.
|
||||
|
||||
The 3 steps [parameter expansion](/syntax/pe), [arithmetic
|
||||
expansion](/syntax/expansion/arith) and [command
|
||||
substitution](/syntax/expansion/cmdsubst) happen at the same time in a
|
||||
The 3 steps [parameter expansion](/syntax/pe.md), [arithmetic
|
||||
expansion](/syntax/expansion/arith.md) and [command
|
||||
substitution](/syntax/expansion/cmdsubst.md) happen at the same time in a
|
||||
left-to-right fashion on nthe commandline. This means
|
||||
|
||||
i=1
|
||||
|
@ -10,11 +10,11 @@ of a process (some sequence of commands) appear as a temporary file.
|
||||
>( <LIST> )
|
||||
|
||||
Process substitution is performed **simultaneously** with [parameter
|
||||
expansion](/syntax/pe), [command
|
||||
substitution](/syntax/expansion/cmdsubst) and [arithmetic
|
||||
expansion](/syntax/expansion/arith).
|
||||
expansion](/syntax/pe.md), [command
|
||||
substitution](/syntax/expansion/cmdsubst.md) and [arithmetic
|
||||
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
|
||||
|
||||
- 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`
|
||||
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
|
||||
[here documents](/syntax/redirection#here_documents).
|
||||
[here documents](/syntax/redirection.md#here_documents).
|
||||
|
||||
``` bash
|
||||
: < <(COMMAND) # Good.
|
||||
@ -179,7 +179,7 @@ ${dev[${dev='dev[1>(${dev[dev]})]'}]}
|
||||
## See also
|
||||
|
||||
- Internal: [Introduction to expansion and
|
||||
substitution](/syntax/expansion/intro)
|
||||
- Internal: [Bash in the process tree](/scripting/processtree)
|
||||
substitution](/syntax/expansion/intro.md)
|
||||
- Internal: [Bash in the process tree](/scripting/processtree.md)
|
||||
(subshells)
|
||||
- Internal: [Redirection](/syntax/redirection)
|
||||
- Internal: [Redirection](/syntax/redirection.md)
|
||||
|
@ -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
|
||||
[PATH](/syntax/shellvars#PATH):
|
||||
[PATH](/syntax/shellvars.md#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
|
||||
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
|
||||
(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:
|
||||
|
||||
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
|
||||
last `cd`). If `OLDPWD` is unset (never changed the directory), it is
|
||||
not expanded.
|
||||
@ -107,4 +107,4 @@ not expanded.
|
||||
## See also
|
||||
|
||||
- Internal: [Introduction to expansion and
|
||||
substitution](/syntax/expansion/intro)
|
||||
substitution](/syntax/expansion/intro.md)
|
||||
|
@ -5,9 +5,9 @@ FIXME to be continued!
|
||||
Word splitting occurs once any of the following expansions are done (and
|
||||
only then!)
|
||||
|
||||
- [Parameter expansion](/syntax/pe)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith)
|
||||
- [Parameter expansion](/syntax/pe.md)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst.md)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith.md)
|
||||
|
||||
Bash will scan the results of these expansions for special `IFS`
|
||||
characters that mark word boundaries. This is only done on results that
|
||||
@ -43,5 +43,5 @@ solely responsible.
|
||||
|
||||
## See also
|
||||
|
||||
- [Introduction to expansion and substitution](/syntax/expansion/intro)
|
||||
- [Quoting and escaping](/syntax/quoting)
|
||||
- [Introduction to expansion and substitution](/syntax/expansion/intro.md)
|
||||
- [Quoting and escaping](/syntax/quoting.md)
|
||||
|
@ -4,7 +4,7 @@ FIXME work in progress...
|
||||
|
||||
![](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
|
||||
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
|
||||
`WORD=WORD`
|
||||
- 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
|
||||
**name of the command** and the remaining words are the
|
||||
**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
|
||||
expansion](/syntax/expansion/tilde), [parameter
|
||||
expansion](/syntax/pe), [command
|
||||
substitution](/syntax/expansion/cmdsubst), [arithmetic
|
||||
expansion](/syntax/expansion/arith), and quote removal before being
|
||||
expansion](/syntax/expansion/tilde.md), [parameter
|
||||
expansion](/syntax/pe.md), [command
|
||||
substitution](/syntax/expansion/cmdsubst.md), [arithmetic
|
||||
expansion](/syntax/expansion/arith.md), and quote removal before being
|
||||
assigned to the variable.
|
||||
|
||||
If **no command name** results after expansion:
|
||||
@ -119,6 +119,6 @@ FIXME to be continued
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [Redirection](/syntax/redirection)
|
||||
- Internal: [Redirection](/syntax/redirection.md)
|
||||
- Internal: [Introduction to expansions and
|
||||
substitutions](/syntax/expansion/intro)
|
||||
substitutions](/syntax/expansion/intro.md)
|
||||
|
@ -4,14 +4,14 @@
|
||||
|
||||
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)
|
||||
- Pattern matching in [conditional
|
||||
expressions](/syntax/ccmd/conditional_expression)
|
||||
- [Substring removal](/syntax/pe#substring_removal) and [search and
|
||||
replace](/syntax/pe#search_and_replace) in [Parameter
|
||||
Expansion](/syntax/pe)
|
||||
- Pattern-based branching using the [case command](/syntax/ccmd/case)
|
||||
expressions](/syntax/ccmd/conditional_expression.md)
|
||||
- [Substring removal](/syntax/pe.md#substring_removal) and [search and
|
||||
replace](/syntax/pe.md#search_and_replace) in [Parameter
|
||||
Expansion](/syntax/pe.md)
|
||||
- Pattern-based branching using the [case command](/syntax/ccmd/case.md)
|
||||
|
||||
The pattern description language is relatively easy. Any character
|
||||
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
|
||||
|
||||
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
|
||||
patterns, separated by the pipe-symbol (`PATTERN|PATTERN`).
|
||||
|
||||
@ -99,13 +99,13 @@ patterns, separated by the pipe-symbol (`PATTERN|PATTERN`).
|
||||
|
||||
| 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 |
|
||||
| `failglob` | [globbing](/syntax/expansion/globs) | see [Pathname expansion customization](/syntax/expansion/globs#Customization) |
|
||||
| `nocaseglob` | [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.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
|
||||
| `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) |
|
||||
| `globasciiranges` | [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.md) | see [Pathname expansion customization](/syntax/expansion/globs.md#Customization) |
|
||||
|
||||
## Bugs and Portability considerations
|
||||
|
||||
|
48
syntax/pe.md
48
syntax/pe.md
@ -9,7 +9,7 @@ is an entity that stores values and is referenced by a **name**, a
|
||||
**number** or a **special symbol**.
|
||||
|
||||
- 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**
|
||||
and reflect the arguments given to a shell
|
||||
- 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
|
||||
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,
|
||||
[see the dictionary entry for "parameter"](/dict/terms/parameter).
|
||||
@ -113,7 +113,7 @@ positional parameters (arguments to a script) beyond `$9`:
|
||||
|
||||
### 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
|
||||
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
|
||||
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
|
||||
[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)`
|
||||
|
||||
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
|
||||
mass-expand** the whole array using `@` or `*` subscripts. Some
|
||||
examples:
|
||||
@ -274,7 +274,7 @@ This will show all defined variable names (not values!) beginning with
|
||||
$ echo ${!BASH*}
|
||||
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
|
||||
|
||||
@ -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
|
||||
pattern to describe what to remove** from the string. The pattern is
|
||||
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*):
|
||||
|
||||
@ -299,7 +299,7 @@ Example string (*just a quote from a big man*):
|
||||
|
||||
`${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 "`#`"
|
||||
will try to remove the shortest text matching the pattern, while "`##`"
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
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}`
|
||||
|
||||
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
|
||||
example string for the tests:
|
||||
|
||||
@ -437,7 +437,7 @@ specifying an empty replacement:
|
||||
|
||||
### 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
|
||||
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
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
`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!
|
||||
|
||||
Example string (a quote from a big man):
|
||||
@ -543,7 +543,7 @@ the colon:
|
||||
${MYSTRING:(-10):5}
|
||||
|
||||
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
|
||||
|
||||
@ -557,11 +557,11 @@ then:
|
||||
`<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
|
||||
[bashchanges](/scripting/bashchanges).
|
||||
[bashchanges](/scripting/bashchanges.md).
|
||||
|
||||
### 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 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
|
||||
|
||||
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
|
||||
given index and mass-expanding the array using the `@` and `*`
|
||||
subscripts.
|
||||
@ -669,7 +669,7 @@ Example code (please try the example cases yourself):
|
||||
`${PARAMETER=WORD}`
|
||||
|
||||
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
|
||||
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
|
||||
@ -691,7 +691,7 @@ Let's change our code example from above:
|
||||
|
||||
### 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
|
||||
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
|
||||
@ -740,7 +740,7 @@ if variables you need (and that can be empty) are undefined:
|
||||
|
||||
### 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
|
||||
individual array elements by index, but reacts differently when using
|
||||
the mass-expansion subscripts `@` and `*`:
|
||||
@ -816,8 +816,8 @@ Removing the first 6 characters from a text string:
|
||||
`${arr[@]}`, `$*`, and `${arr[*]}` when
|
||||
[IFS](http://mywiki.wooledge.org/IFS) is set to null. POSIX is unclear
|
||||
about the expected behavior. A null IFS causes both [word
|
||||
splitting](/syntax/expansion/wordsplit) and [pathname
|
||||
expansion](/syntax/expansion/globs) to behave randomly. Since there
|
||||
splitting](/syntax/expansion/wordsplit.md) and [pathname
|
||||
expansion](/syntax/expansion/globs.md) to behave randomly. Since there
|
||||
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 `$*`
|
||||
unquoted, this should be a rare issue. **Always quote
|
||||
@ -1040,5 +1040,5 @@ the difference may introduce a possible compatibility problem.
|
||||
## See also
|
||||
|
||||
- Internal: [Introduction to expansion and
|
||||
substitution](/syntax/expansion/intro)
|
||||
- Internal: [Arrays](/syntax/arrays)
|
||||
substitution](/syntax/expansion/intro.md)
|
||||
- Internal: [Arrays](/syntax/arrays.md)
|
||||
|
@ -71,14 +71,14 @@ below).
|
||||
Inside a weak-quoted string there's **no special interpretion of**:
|
||||
|
||||
- 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)
|
||||
- characters for pattern matching
|
||||
- tilde expansion
|
||||
- pathname expansion
|
||||
- process substitution
|
||||
|
||||
Everything else, especially [parameter expansion](/syntax/pe), is
|
||||
Everything else, especially [parameter expansion](/syntax/pe.md), is
|
||||
performed!
|
||||
|
||||
ls -l "*"
|
||||
@ -197,7 +197,7 @@ documentation](http://www.gnu.org/software/gettext/manual/html_node/bash.html)
|
||||
|
||||
### 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:
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
|
||||
[ WORD = WORD ]
|
||||
@ -259,13 +259,13 @@ Now the command has three parameters, which makes sense for a binary
|
||||
(two argument) operator.
|
||||
|
||||
**<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
|
||||
references - they are always seen as "one word".
|
||||
|
||||
## See also
|
||||
|
||||
- Internal: [Some words about words...](/syntax/words)
|
||||
- Internal: [Word splitting](/syntax/expansion/wordsplit)
|
||||
- Internal: [Some words about words...](/syntax/words.md)
|
||||
- Internal: [Word splitting](/syntax/expansion/wordsplit.md)
|
||||
- Internal: [Introduction to expansions and
|
||||
substitutions](/syntax/expansion/intro)
|
||||
substitutions](/syntax/expansion/intro.md)
|
||||
|
@ -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
|
||||
that, together with pipelines, makes the shell powerful. The redirection
|
||||
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
|
||||
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.
|
||||
|
||||
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
|
||||
override that behaviour by forcing overwrite with the redirection
|
||||
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
|
||||
used. See the page about [obsolete and deprecated
|
||||
syntax](/scripting/obsolete).\</wrap\>
|
||||
syntax](/scripting/obsolete.md).\</wrap\>
|
||||
|
||||
## 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
|
||||
substitutions and expansions are performed in the here-document data:
|
||||
|
||||
- [Parameter expansion](/syntax/pe)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith)
|
||||
- [Parameter expansion](/syntax/pe.md)
|
||||
- [Command substitution](/syntax/expansion/cmdsubst.md)
|
||||
- [Arithmetic expansion](/syntax/expansion/arith.md)
|
||||
|
||||
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
|
||||
|
||||
- Internal: [Illustrated Redirection
|
||||
Tutorial](/howto/redirection_tutorial)
|
||||
- Internal: [The noclobber option](/commands/builtin/set#tag_noclobber)
|
||||
- Internal: [The exec builtin command](/commands/builtin/exec)
|
||||
Tutorial](/howto/redirection_tutorial.md)
|
||||
- Internal: [The noclobber option](/commands/builtin/set.md#tag_noclobber)
|
||||
- Internal: [The exec builtin command](/commands/builtin/exec.md)
|
||||
- Internal: [Simple commands parsing and
|
||||
execution](/syntax/grammar/parser_exec)
|
||||
- Internal: [Process substitution syntax](/syntax/expansion/proc_subst)
|
||||
- Internal: [Obsolete and deprecated syntax](/scripting/obsolete)
|
||||
execution](/syntax/grammar/parser_exec.md)
|
||||
- Internal: [Process substitution syntax](/syntax/expansion/proc_subst.md)
|
||||
- Internal: [Obsolete and deprecated syntax](/scripting/obsolete.md)
|
||||
|
@ -15,7 +15,7 @@
|
||||
<td><code>*</code></td>
|
||||
<td>asterisk</td>
|
||||
<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
|
||||
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 />
|
||||
@ -26,26 +26,26 @@ delimiter.<br />
|
||||
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
|
||||
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>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
<td><code>@</code></td>
|
||||
<td>at-sign</td>
|
||||
<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
|
||||
words</em>: <code>"$1" "$2" "$3" "$4"</code><br />
|
||||
Without doublequotes, the behaviour is like the one of <code>*</code>
|
||||
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>
|
||||
</tr>
|
||||
<tr class="odd">
|
||||
<td><code>#</code></td>
|
||||
<td>hash mark</td>
|
||||
<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>
|
||||
</tr>
|
||||
<tr class="even">
|
||||
@ -58,7 +58,7 @@ handling positional parameters</a>.</td>
|
||||
<td><code>-</code></td>
|
||||
<td>dash</td>
|
||||
<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>,
|
||||
<code>i</code>, <code>m</code> and <code>B</code>.</td>
|
||||
</tr>
|
||||
@ -66,7 +66,7 @@ just a set of characters, like <code>himB</code> for <code>h</code>,
|
||||
<td><code>$</code></td>
|
||||
<td>dollar-sign</td>
|
||||
<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
|
||||
different from <code>$BASHPID</code>!</td>
|
||||
</tr>
|
||||
@ -125,7 +125,7 @@ Bash.
|
||||
A colon-separated list of enabled shell options.
|
||||
|
||||
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 the environment when Bash starts up, each shell option in the list
|
||||
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,
|
||||
`${FUNCNAME[$i]}` was called from the file `${BASH_SOURCE[$i+1]}` at
|
||||
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 variable exists only when a shell function is executing.
|
||||
@ -626,7 +626,7 @@ Example content:
|
||||
| Set by Bash: | yes | Default: | n/a |
|
||||
|
||||
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
|
||||
|
||||
@ -739,10 +739,10 @@ with `bind -x`.
|
||||
| Variable: | `REPLY` | Since: | unknown |
|
||||
|:-------------|:-----------------------------------------------------------|:-----------|:--------|
|
||||
| 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
|
||||
command](/commands/builtin/read) when no arguments are supplied that
|
||||
command](/commands/builtin/read.md) when no arguments are supplied that
|
||||
name target variables.
|
||||
|
||||
### SECONDS
|
||||
@ -769,7 +769,7 @@ is subsequently reset.
|
||||
|
||||
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
|
||||
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`.
|
||||
|
||||
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
|
||||
shell, as in `~/.bashrc`. The value of `BASH_ENV` is subjected to
|
||||
|
||||
- [parameter expansion](/syntax/pe)
|
||||
- [command substitution](/syntax/expansion/cmdsubst)
|
||||
- [arithmetic expansion](/syntax/expansion/arith)
|
||||
- [parameter expansion](/syntax/pe.md)
|
||||
- [command substitution](/syntax/expansion/cmdsubst.md)
|
||||
- [arithmetic expansion](/syntax/expansion/arith.md)
|
||||
|
||||
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 value of this variable is also used when performing [tilde
|
||||
expansion](/syntax/expansion/tilde).
|
||||
expansion](/syntax/expansion/tilde.md).
|
||||
|
||||
### HOSTFILE
|
||||
|
||||
@ -1438,7 +1438,7 @@ A trailing newline is added when the format string is displayed.
|
||||
| Set by Bash: | no | Default: | n/a |
|
||||
|
||||
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
|
||||
not arrive after `TMOUT` seconds when input is coming from a terminal.
|
||||
|
@ -89,7 +89,7 @@ take care of the spaces. But Bash also does another type of splitting.
|
||||
## Word splitting
|
||||
|
||||
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
|
||||
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 |
|
||||
| `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
|
||||
splitting](/syntax/expansion/wordsplit) on the results:
|
||||
splitting](/syntax/expansion/wordsplit.md) on the results:
|
||||
|
||||
| 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 =====
|
||||
|
||||
- Internal: [Quoting and character escaping](/syntax/quoting)
|
||||
- Internal: [Word splitting](/syntax/expansion/wordsplit)
|
||||
- Internal: [Quoting and character escaping](/syntax/quoting.md)
|
||||
- Internal: [Word splitting](/syntax/expansion/wordsplit.md)
|
||||
- Internal: [Introduction to expansions and
|
||||
substitutions](/syntax/expansion/intro)
|
||||
substitutions](/syntax/expansion/intro.md)
|
||||
|
@ -46,7 +46,7 @@ bash I found here:
|
||||
|
||||
- <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
|
||||
|
||||
### Getopts tutorial
|
||||
|
Loading…
Reference in New Issue
Block a user