As explained by ridiculous_fish you can use native line-splitting mechanism.
result of a command substitution becomes a list by splitting on newlines (
$IFS
)
So
- list one item per line ;
- then capture that in a command substitution.
Listing
function __list_public_keys
for key in ~/.ssh/*.pub
echo $key
end
end
output
$ __list_public_keys
/home/ed8/.ssh/id_rsa.blabla.pub
/home/ed8/.ssh/id_rsa.pub
/home/ed8/.ssh/id_rsa.test.pub
Capturing
function __add_keys
set keys (__list_public_keys)
echo "[" $keys "]"
end
output
$ __add_keys
[/home/ed8/.ssh/id_rsa.blabla.pub] [/home/ed8/.ssh/id_rsa.pub] [/home/ed8/.ssh/id_rsa.test.pub]