How to capture new lines from command substitution output in fish shell?

In bash, newlines are saved using command substitution:

$ TEST="$(echo 'a
  b
  c
  ')" && echo "$TEST"
# →
a
b
c

However, when I try to do the same in a fish shell, newlines are converted to spaces:

$ set TEST (echo "a
  b
  c
  "); and echo "$TEST"
# →
a b c

How to make fish save newlines as newlines?

+4
source share
1 answer

The exact issue discussed on the mailing list for fish users: The user mailing list is discussed: http://sourceforge.net/p/fish/mailman/message/33644843/

To do this, you need to change the IFS variable:

$ set out (seq 5)
$ echo "$out"
1 2 3 4 5

$ set oldIFS "$IFS"
$ set IFS ""
$ set out (seq 5)
$ echo "$out"
1
2
3
4
5
$ set IFS "$oldIFS"
+1
source

All Articles