小编Dia*_*bor的帖子

在 Bash 中对实用程序的链式调用进行参数化

我有一个在 Bash shell 中使用的黑盒 UNIX 程序,它从标准输入读取数据列,处理它们(应用平滑效果)然后输出到标准输出。我通过 UNIX 管道使用它,比如

generate | smooth | plot  
Run Code Online (Sandbox Code Playgroud)

为了更平滑,我可以重复平滑,所以它会从 Bash 命令行调用

generate | smooth | smooth | plot   
Run Code Online (Sandbox Code Playgroud)

甚至

generate | smooth | smooth | smooth | smooth | smooth | smooth | smooth | smooth | smooth | smooth | plot
Run Code Online (Sandbox Code Playgroud)

这越来越不靠谱了。我想制作一个 Bash 包装器,以便能够将smooth其输出通过管道输入并返回到smooth任意次数的新实例中,例如

generate | newsmooth 5 | plot
Run Code Online (Sandbox Code Playgroud)

代替

generate | smooth | smooth | smooth | smooth | smooth | plot
Run Code Online (Sandbox Code Playgroud)

我的第一次尝试是一个 Bash 脚本,它在当前目录中生成临时文件并删除它们,但是当我不在具有写访问权限的目录中时它变得丑陋,并且在中断时也会留下垃圾文件。

该smooth程序没有参数。 …

bash pipe shell-script

12
推荐指数
2
解决办法
610
查看次数

标签 统计

bash ×1

pipe ×1

shell-script ×1