[SOLVED] In a fish shell function how to pipe stdin to a variable?


Here’s what I got:

function stdin2var
    set a (cat -)
    echo $a

First example:

$ echo 'some text' | stdin2var
# should output "some text"

Second example:

$ echo some text\nsome more text | stdin2var
# should output: "some text
some more text"

Any tips?


In fish shell (and others), you want read:

echo 'some text' | read varname

Answered By – ridiculous_fish

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *