壳管过程重复 [英] shell pipe process repeat

查看:118
本文介绍了壳管过程重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做这样的事情:

~ cat dump.sh
command 1 | command 2 | command 1 | command 2 | ...(ten times) | command 1 | command2

~ ./dump.sh < demo.log

那么如何修改 dump.sh 虽然我可以明确指定 N 次命令1 命令2 中对处理demo.log?

So how to modify dump.sh while I can specify exactly n times of command 1 and command 2 in pair to process demo.log?

推荐答案

您可以编写一个简单的递归辅助函数,是这样的:

You can write a simple recursive helper function, something like this:

loop () {
    case $1 in
      0) cat;;
      *) command 1 | command 2 | loop $(($1 - 1)) ;;
    esac
}

调用它像

loop 3 <demo.log

这篇关于壳管过程重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆