linux - Maintain line breaks in output from subshell -
when execute subshell obtain output of command, line breaks lost.
for example:
filenames=$(grep 'foobar' /some/dir) echo $filenames
assuming there more 1 file in /some/dir
contains string "foobar", filenames printed in 1 long space-separated line instead of 1 filename per line.
i can't use tr
convert spaces line breaks since filenames have spaces in them anyway.
is there way maintain line breaks?
quote variable print newlines:
filenames=$(grep 'foobar' /some/dir) echo "$filenames"
Comments
Post a Comment