retry_wrapper.sh

Shellマスター

Explorer

C40
C++40
C#40
Dart40
Go40
Java40
JavaScript40
Kotlin40
Objective-C40
Perl40
PHP40
Python40
R40
Ruby40
Rust40
Shell
初級10
中級10
上級10
エキスパート5
マスター5
parallel_batch.sh
trap_cleanup.sh
json_parser.sh
config_loader.sh
retry_wrapper.sh
Swift40
TypeScript40
retry_wrapper.sh
Click to focus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
retry() {
   local -r max_attempts="${1:-3}"
   local -r delay="${2:-5}"
   local attempt=1
   shift 2
   until "$@"; do
       if (( attempt >= max_attempts )); then
           echo "Failed after $attempt attempts" >&2
           return 1
       fi
       echo "Attempt $attempt failed, retrying in ${delay}s..." >&2
       sleep "$delay"
       ((attempt++))
   done
}
retry 5 2 curl -f "https://api.example.com/health"
0WPM0%0:000/421(0%)|Ln 1, Col 1
UTF-8Shell

関連する練習問題