If you want to store stdin into a scalar variable:
function stdin2var
read -l -z a
set --show a
echo $a
end
echo some text\nsome more text | stdin2var
# $a: set in local scope, unexported, with 1 elements
# $a[1]: length=25 value=|some text\nsome more text\n|
# some text
# some more text
If you want to split lines in to a array:
function stdin2var
set -l a
IFS=\n read -az a
set --show a
for line in $a
echo $line
end
end
echo some text\nsome more text | stdin2var
# $a: set in local scope, unexported, with 2 elements
# $a[1]: length=9 value=|some text|
# $a[2]: length=14 value=|some more text|
# some text
# some more text