2023-07-05 11:43:35 +02:00
|
|
|
# Word splitting
|
|
|
|
|
2024-10-08 06:00:17 +02:00
|
|
|
!!! warning "FIXME"
|
|
|
|
to be continued!
|
2023-07-05 11:43:35 +02:00
|
|
|
|
|
|
|
Word splitting occurs once any of the following expansions are done (and
|
|
|
|
only then!)
|
|
|
|
|
2024-01-29 02:07:56 +01:00
|
|
|
- [Parameter expansion](../../syntax/pe.md)
|
|
|
|
- [Command substitution](../../syntax/expansion/cmdsubst.md)
|
|
|
|
- [Arithmetic expansion](../../syntax/expansion/arith.md)
|
2023-07-05 11:43:35 +02:00
|
|
|
|
|
|
|
Bash will scan the results of these expansions for special `IFS`
|
|
|
|
characters that mark word boundaries. This is only done on results that
|
|
|
|
are **not double-quoted**!
|
|
|
|
|
|
|
|
## Internal Field Separator IFS
|
|
|
|
|
|
|
|
The `IFS` variable holds the characters that Bash sees as word
|
|
|
|
boundaries in this step. The default contains the characters
|
|
|
|
|
2024-10-08 06:00:17 +02:00
|
|
|
- <space>
|
|
|
|
- <tab>
|
|
|
|
- <newline>
|
2023-07-05 11:43:35 +02:00
|
|
|
|
|
|
|
These characters are also assumed when IFS is **unset**. When `IFS` is
|
|
|
|
**empty** (nullstring), no word splitting is performed at all.
|
|
|
|
|
|
|
|
## Behaviour
|
|
|
|
|
|
|
|
The results of the expansions mentioned above are scanned for
|
|
|
|
`IFS`-characters. If **one or more** (in a sequence) of them is found,
|
|
|
|
the expansion result is split at these positions into multiple words.
|
|
|
|
|
2024-03-30 20:09:26 +01:00
|
|
|
This doesn't happen when the expansion results were **double-quoted**.
|
2023-07-05 11:43:35 +02:00
|
|
|
|
|
|
|
When a null-string (e.g., something that before expanded to
|
2024-10-08 06:00:17 +02:00
|
|
|
>>nothing<<) is found, it is removed, unless it is quoted (`''` or
|
2023-07-05 11:43:35 +02:00
|
|
|
`""`).
|
|
|
|
|
2024-10-08 06:00:17 +02:00
|
|
|
<u>**Again note:**</u> Without any expansion beforehand, Bash
|
2024-03-30 20:09:26 +01:00
|
|
|
won't perform word splitting! In this case, the initial token parsing
|
2023-07-05 11:43:35 +02:00
|
|
|
is solely responsible.
|
|
|
|
|
|
|
|
## See also
|
|
|
|
|
|
|
|
- [Introduction to expansion and
|
2024-01-29 02:07:56 +01:00
|
|
|
substitution](../../syntax/expansion/intro.md)
|
|
|
|
- [Quoting and escaping](../../syntax/quoting.md)
|
2023-07-05 11:43:35 +02:00
|
|
|
- [WordSplitting](http://mywiki.wooledge.org/WordSplitting),
|
|
|
|
[IFS](http://mywiki.wooledge.org/IFS), and
|
|
|
|
[DontReadLinesWithFor](http://mywiki.wooledge.org/DontReadLinesWithFor) -
|
2024-03-30 19:22:45 +01:00
|
|
|
Greg's wiki
|