首页 > 解决方案 > 在鱼壳函数中,如何将标准输入通过管道传输到变量?

问题描述

这是我得到的:

function stdin2var
    set a (cat -)
    echo $a
end

第一个例子:

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

第二个例子:

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

有小费吗?

标签: functionfish

解决方案


在鱼壳(和其他)中,你想要read

echo 'some text' | read varname

推荐阅读