这是我得到的:
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"
有小费吗?
最佳答案
在 fish shell (和其他)中,你想要 read
:
echo 'some text' | read varname
关于function - 在 fish shell 函数中如何通过管道将标准输入传递给变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61947162/