Bash Script: A way to wait_until

Use wait_until function in daily Linux work.

wait_until() { local fn=$1; for ((;;)); do $fn && { echo "OK"; break; } || { sleep 1; echo -n "."; } done; }
<<"EOF"
Usage:
    <terminal>
    $ file_bar_exists() { [[ -f bar.txt ]]; }
    $ wait_until file_bar_exists
    .......  # <-- changing all the time

    <another terminal>
    $ touch bar.txt

    <terminal>
    $ wait_until file_bar_exists
    .................OK  # <-- OK and new line append
    $
EOF


你可能感兴趣的:(command,bash)