function - 在 fish shell 函数中如何通过管道将标准输入传递给变量?

标签 function fish

这是我得到的:

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/

相关文章:

c++ - 读取文件然后创建数组函数 C++

c++ - 如何理解 C++ 中的_Function_class_(name)

bash - 如何在 fish shell 中生成字母序列表

shell - 为什么 Fish shell 将深蓝色作为目录的默认颜色

Fish动态定义一个函数

javascript - function() 和 $(this) 中的 each()

javascript - 使用 function.bind 将函数绑定(bind)到 this

TIDE 内的 Fish shell git 提示符

c - 关于在数组中查找最大的函数问题

fish - 在 fish shell 中同时管道 stdout 和 stderr