STRING-SPLIT0(1)
π STRING-SPLIT0(1) β the fish-shell one, bestie β¨
okay so this is a page from the fish-shell manual, and it's all about splitting strings. yes it's string-split0 but like... it's also string split and string split0, we're doing both. buckle up π
πΈ NAME πΈ
string-split0 β splitting on zero bytes, that's the whole vibe, no cap.
β¨ SYNOPSIS β¨
string split [(-f | --fields) FIELDS [-a | --allow-empty]] [(-m | --max) MAX] [-n | --no-empty]
[-q | --quiet] [-r | --right] SEP [STRING ...]
string split0 [(-f | --fields) FIELDS [-a | --allow-empty]] [(-m | --max) MAX] [-n | --no-empty]
[-q | --quiet] [-r | --right] [STRING ...]
like yes, that's a lot of brackets, but it's giving "choose your own adventure" and honestly we love that π
π¦ DESCRIPTION π¦
so string split literally splits each STRING on the separator SEP β and yes, SEP can be an empty string, it's fine, it's allowed, it's iconic π«Ά
-m,--maxβ if you pass this, at most MAX splits get done on each STRING. that's the cap, periodt.-r,--rightβ this one does the splitting right-to-left. and lowkey? it's only actually useful when you pair it with-mor--max, so don't use it alone and expect magic, bestie π-n,--no-emptyβ empty results get excluded from consideration. like,hello\n\nworldexpands to two strings, not three. bye empty field, you will not be missed β¨
Exit status: 0 if at least one split was performed, or 1 otherwise. that's the vibe check, fr fr.
now the fancy part π
β use -f or --fields to print out specific fields. FIELDS is a comma-separated string of field numbers and/or spans. each field is one-indexed, and gets printed on separate lines. so if a given field doesn't exist, the command exits with status 1 and does not print anything β unless you used --allow-empty, in which case it's chillin π
also see the--delimiteroption of thereadcommand, iykyk π
string split0 splits each STRING on the zero byte (NUL). options are the same as string split except β plot twist β no separator is given. because the separator is the NUL. it's built in. she doesn't need you to tell her π
split0 has this super important property: its output is not further split when used in a command substitution. meaning the command substitution can produce elements containing newlines. that is the main character energy right there π this is most useful with Unix tools that produce zero bytes, like find -print0 or sort -z. check the split0 examples below, they ate π₯
be aware though, for real: commandline arguments cannot include NULs. so you probably want to pass to string split0 via a pipe, not a command substitution. don't do the cursed thing, bestie π
π EXAMPLES π
>_ string split . example.com
example
com
>_ string split -r -m1 / /usr/local/bin/fish
/usr/local/bin
fish
>_ string split '' abc
a
b
c
>_ string split --allow-empty -f1,3-4,5 '' abcd
a
c
d
look at that. clean. slay. πΈ
π NUL Delimited Examples π
>_ # Count files in a directory, without being confused by newlines.
>_ # Note: Don't use `string split0 (find . -print0)`, because arguments cannot include NUL.
>_ count (find . -print0 | string split0)
42
>_ # Sort a list of elements which may contain newlines
>_ set foo beta alpha\ngamma
>_ set foo (string join0 $foo | sort -z | string split0)
>_ string escape $foo[1]
alpha\ngamma
see that 42? iconic. and that alpha\ngamma surviving as one element? chef's kiss π§β¨
π Copyright π
fish-shell developers β they made this, we're just vibing with it π«Ά
and that's the whole page, bestie! brought to you by fish-shell, version 4.9, dated Sep 08, 2026 β go split something responsibly ππ·β
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms