function - 在鱼壳函数中,如何将标准输入通过管道传输到变量?
问题描述
这是我得到的:
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"
有小费吗?
解决方案
在鱼壳(和其他)中,你想要read
:
echo 'some text' | read varname
推荐阅读
- django - 使用 ngix 和 uwsgi 的问题
- c - ThreadSanitaizer 未检测到 lock_cmpxchg 并警告数据争用
- ubuntu - 运行 Ansible playbook 时出现错误安装请求库
- bash - 流解压到拆分
- json - ListiewBuilder 下的单选按钮未正确选择项目
- conda - 如何删除未出现在 jupyterlab 的 conda env 列表中的 conda 环境?
- mysql - 使用 nvarchar(max) 类型将 MSSQL SERVER 迁移到 MY SQL
- security - .net core 3.1 api 子域安全响应标头
- git - 更改 git 存储库哈希函数?
- android - 为什么 Android 版 MoveNet 的性能比网页版差?