${(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
.
Links
Examples
- Split string with newlines into fields
- Output:
1 2 3 4
# contains \n value="$(ls -1)" # each line contained in $value is split into a field echo "Contents: ${(f)value}"
1
Contents: temp file1.txt file2.txt
BashSupport Pro is a Zsh IDE with support for ${(f)…} – try it now!