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 πŸ’–

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