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
date? How are you actually incrementingseconds?elifclause available, so that you don't have to nestifstatements like this.((and if's with? :ternary operator.(( hours == 23 && minutes == 60 && seconds == 60 && ( seconds = 0, minutes = 0, hours = 0, date++ ) )).to 23:59:59- then you should compare with59not with60."$hours" -eq 23should be"$hours" -eq 24. You're testing the value after it has been incremented.22:59:59to0:0:0.