How would I tell a bash script to start over from the top?

bash, linux, repeat

Solution

Put it in a while loop. I'd also suggest you add a "sleep" so that you're not racing your machine's CPU as fast as it will go:

while true; do
    ##########################################################################
    ## CHECK TIME
    ##########################################################################
    time=$(date +%k%M)

    if [[ "$time" -ge 1800 ]] && [[ "$time" -le 2200 ]]; then
        echo "Not a good time to transcode video!" && exit 0
    else
        echo "Excellent time to transcode video!" && echo "Lets get started!"
    fi
    ##########################################################################
    ## CHECK TIME
    ##########################################################################
    for i in {1..5}; do
        echo $i
        sleep 1
    done
done

Problem

For example, in the below script `startover` starts back from the top: ``` ########################################################################## ## CHECK TIME ########################################################################## time=$(date +%k%M) if [[ "$time" -ge 1800 ]] && [[ "$time" -le 2200 ]];then echo "Not a good time to transcode video!" && exit 0 else echo "Excellent time to transcode video!" && echo "Lets get started!" fi ########################################################################## ## CHECK TIME ########################################################################## startover ``` Also keeping in mind `exit 0` should be able to stop the script.

Original source