0

I saved output of diff to variable variable=$(diff file1 file2)

When printing using echo "$variable", there appears text with new lines:

1c1
< x
---
> y

but when using echo $variable, everything stays in one line.

1c1 < x --- > y

I wonder what is a reason of this difference.

prenc
  • 151
  • 2
  • 13

1 Answers1

0

A possible solution to your query is at: https://unix.stackexchange.com/a/124638/41427

Compare

$ echo $(printf 'foo\nbar\nquux\n*')
foo bar quux ssh-13yzvBMwVYgn ssh-3JIxkphQ07Ei ssh-6YC5dbnk1wOc 

with

$ echo "$(printf 'foo\nbar\nquux\n*')"
foo
bar
quux
*

Again quoting:

Without quotes the string is subject to word splitting and globbing . See also BashPitfalls #14.

Menelaos
  • 23,508
  • 18
  • 90
  • 155