Post

シェルで無限ループする時のテンプレート

解決

#!/bin/bash function randbool() { if (( RANDOM %2 )); then true else false fi } while : do randbool if [ $? -eq 0 ]; then echo 'break' break else echo "wait 1 sec." sleep 1 fi done
$ infinity_loop.sh
wait 1 sec.
wait 1 sec.
wait 1 sec.
wait 1 sec.
break

Bash: Random numbers for fun and profit

This post is licensed under CC BY 4.0 by the author.