Replace set var (command)
with set var (command | string split0)
Explanation:
command substition splits on newlines by default. The $response variable is a list of lines of the output. This is documented
$ set var (seq 10)
$ set --show var
$var: not set in local scope
$var: set in global scope, unexported, with 10 elements
$var[1]: length=1 value=|1|
$var[2]: length=1 value=|2|
$var[3]: length=1 value=|3|
$var[4]: length=1 value=|4|
$var[5]: length=1 value=|5|
$var[6]: length=1 value=|6|
$var[7]: length=1 value=|7|
$var[8]: length=1 value=|8|
$var[9]: length=1 value=|9|
$var[10]: length=2 value=|10|
$var: not set in universal scope
Fortunately so is the remedy
$ set var (seq 10 | string split0)
$ set -S var
$var: not set in local scope
$var: set in global scope, unexported, with 1 elements
$var[1]: length=21 value=|1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n|
$var: not set in universal scope
OR
$ set oldIFS $IFS
$ set --erase IFS
$ set var (seq 10)
$ set -S var
$var: not set in local scope
$var: set in global scope, unexported, with 1 elements
$var[1]: length=20 value=|1\n2\n3\n4\n5\n6\n7\n8\n9\n10|
$var: not set in universal scope
$ set IFS $oldIFS
Note the difference with the string split0
keeping the trailing newline.
If you're OK with $response being a list of lines, but you just want to display it properly:
printf "%s\n" $response
or, with just a literal newline as the join string
string join "
" $respose
string split0
before capturing” ? – Chris F Carroll Aug 11 '20 at 14:35set var (echo -e "line1\nline2" | string split0)
– Alex Fedulov Apr 19 '23 at 14:37