STRING-COLLECT(1)
π STRING-COLLECT(1) π
okay so this is a fish-shell manual page, and honestly? it's lowkey one of the most useful little gremlins in the whole toolbox. bestie, let's get into it β¨
πΈ NAME πΈ
string-collect β join strings into one π«Ά
β¨ SYNOPSIS β¨
string collect [-a | --allow-empty] [-N | --no-trim-newlines] [STRING ...]
π DESCRIPTION π
So string collect does exactly what it says on the tin: it scoops up all its input and collects it into a single output argument, and crucially it does not split that output when you use it inside a command substitution. no cap, that's the whole vibe. π
Why do you care? because it's chef's kiss for collecting multiline output from some other command straight into a variable. that's the main character use case fr.
Exit status: 0 if any output argument is non-empty, or 1 otherwise. simple as that π
A command like echo (cmd | string collect) is mostly equivalent to a quoted command substitution, like echo "$(cmd)". the one main difference? the former evaluates to zero or one elements, whereas the quoted command substitution always evaluates to one element, thanks to string interpolation. iykyk π
If you invoke it with multiple arguments instead of piping in input, string collect keeps each argument separate β the number of output arguments is equal to the number of arguments you handed it. it's giving "respect the individual" energy β¨
Any trailing newlines on the input get trimmed, just like what happens with "$(cmd)" substitution. want to turn that off? hit it with --no-trim-newlines, which is handy when you're running something like:
set contents (cat filename | string collect -N)
And with --allow-empty, string collect always prints one (empty) argument. use it so your argument doesn't just vanish into the void π«₯π
π the flags, one by one π
-a,--allow-emptyβ always prints one (empty) argument, so an argument can't disappear on you π-N,--no-trim-newlinesβ turns off the trailing-newline trimming, so those newlines stay put π¦
π EXAMPLES π
okay these are iconic, watch closely:
>_ echo "zero $(echo one\ntwo\nthree) four"
zero one
two
three four
>_ echo \"(echo one\ntwo\nthree | string collect)\"
"one
two
three"
>_ echo \"(echo one\ntwo\nthree | string collect -N)\"
"one
two
three
"
>_ echo foo(true | string collect --allow-empty)bar
foobar
see how the -N version keeps that extra newline before the closing quote? that's the whole point bestie π
π Copyright π
fish-shell developers π
and that's the page!! slay π this is fish-shell 4.9, dated Sep 08, 2026 β go forth and collect your strings, queen ππ
π¦ 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