跳至内容
人工大脑
好记性不如烂 Wiki
用户工具
登录
站点工具
搜索
工具
显示页面
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
shell-retry
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== 在 shell 中重试 ====== 参考 ((http://fahdshariff.blogspot.com/2014/02/retrying-commands-in-shell-scripts.html)) 注意代码是 GPL 的 <code bash> #!/bin/bash # Retries a command on failure. # $1 - the max number of attempts # $2... - the command to run retry() { local -r -i max_attempts="$1"; shift local -r cmd="$@" local -i attempt_num=1 until $cmd do if (( attempt_num == max_attempts )) then echo "Attempt $attempt_num failed and there are no more attempts left!" return 1 else echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..." sleep $(( attempt_num++ )) fi done } # example usage: retry 5 ls -ltr foo </code> {{tag>shell bash}}
shell-retry.txt
· 最后更改: 2021-11-23 02:56:56 由
三三
页面工具
显示页面
反向链接
回到顶部