${(f)…}: Split at newlines

(f) splits the expanded result at newlines (\n).

${(f)name} is equivalent to ${(ps:\n:)name}.

(F) is performing the reverse: it’s joining elements of arrays into a single string with \n.

Examples

Split string with newlines into fields
1
2
3
4
# contains \n
value="$(ls -1)"
# each line contained in $value is split into a field
echo "Contents: ${(f)value}"
Output:
1
Contents: temp file1.txt file2.txt
BashSupport Pro is a Zsh IDE with support for ${(f)…}try it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal