pockestrap

Programmer's memo

exit status が0である間コマンドを繰り返す

id:sinsoku さんのツイートを見て思いついた。

作った

# exit statusが0であれば、指定した回数繰り返す
$ crepeat 10 echo hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello

# 適当にexit 1するとrepeatがとまる。
$ crepeat 10 ruby -e 'p "a"; exit [true,false].sample'
"a"
"a"

# 回数に負の値を指定すると、無限にexit statusが0の間無限にrepeatする
$ crepeat -1 echo hello
hello
hello
hello
hello
hello
....