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 -m or --max, so don't use it alone and expect magic, bestie πŸ™ˆ
  • -n, --no-empty β€” empty results get excluded from consideration. like, hello\n\nworld expands 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 --delimiter option of the read command, 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 🧚✨


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