重复运行shell命令,直到失败? [英] Repeatedly run a shell command until it fails?

查看:104
本文介绍了重复运行shell命令,直到失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了模糊测试,该测试失败了.我添加了一些调试代码,但是现在我想运行测试直到失败,这样我才能收集调试输出.

I've written a fuzzy test that fails unreliably. I've added some debug code, but now I want to run the test until it fails so I can gather the debug output.

我已经设置了测试,因此可以使用以下命令来运行它:

I've setup the test so I can run it using:

./runtest

我当前的解决方案是编写一个untilfail脚本:

My current solution is to write an untilfail script:

#!/bin/bash
$@
while [ $? -eq 0 ]; do
    $@
done

然后使用它:

untilfail ./runtest

有没有更简单的解决方案?

Is there a simpler solution?

推荐答案

while需要执行命令,因此您可以使用更简单的

while takes a command to execute, so you can use the simpler

while ./runtest; do :; done

./runtest返回 nonzero 退出代码(通常表示失败)时,这将停止循环.

This will stop the loop when ./runtest returns a nonzero exit code (which is usually indicative of failure).

不过,为了进一步简化您当前的解决方案,您只需更改您的直到失败脚本,如下所示:

To further simplify your current solution though, you should just change your untilfail script to look like this:

#!/bin/bash

while "$@"; do :; done

然后您可以使用已在使用的任何命令来调用它:

And then you can call it with whatever command you're already using:

untilfail ./runTest --and val1,val2 -o option1 "argument two"

这篇关于重复运行shell命令,直到失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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