lundi 10 février 2020

Bash if statement with multiple variables

Hello I am trying to make a simple bash script and am very new to it.

With the the if statement I am trying to count up like a clock.

So the output would be for example 16:59:58, 16:59:59, 17:00:00

The seconds and minutes work, however the first if statement is not working.

When it gets to 23:59:59, it is meant to go to 00:00:00 however it goes to 24:60:00

Any help?

if [[ "$hours" -eq 23 && "$minutes" -eq 60 && "$seconds" -eq 60 ]]
then
    seconds=0
    minutes=0
    hours=0
    ((date++))
else
    if [[ "$minutes" -eq 60 ]]
    then
        minutes=00
        ((hours++))
    else
        if [[ "$seconds" -eq 60 ]]
        then
            seconds=00
            ((minutes++))
        fi
    fi
fi

Aucun commentaire:

Enregistrer un commentaire