2025-03-14 21:59:59 -06:00
|
|
|
# IFS
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
> `$IFS` (Internal Field Separator) is a special environment variable that defines the delimiter used for word splitting in Unix shells.
|
|
|
|
|
> The default value of `$IFS` is a space, tab, and newline. The three characters serve as delimiters.
|
2025-12-16 10:20:31 -07:00
|
|
|
> More information: <https://www.gnu.org/software/bash/manual/bash.html#Word-Splitting>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- View the current `$IFS` value:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
`echo "$IFS"`
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- Change the `$IFS` value:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
`IFS="{{:}}"`
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- Reset `$IFS` to default:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
`IFS=$' \t\n'`
|
|
|
|
|
|
2026-02-18 06:55:01 -07:00
|
|
|
- Temporarily change the `$IFS` value in a subshell:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
`(IFS="{{:}}"; echo "{{one:two:three}}")`
|