Understand script

I am trying to understand what this is doing.

I know that it waits 300 seconds.

Is it also waiting 50 hours?

sleep 300s
while true
do
  ukuu --notify ; sleep 50h 
done

Sleeps for 300 seconds,
then runs infinite loop
Why is this infinite loop?
Every command returns an exit status (sometimes referred to as a return status or exit code).
A successful command returns a 0, while an unsuccessful one returns a non-zero value that usually can be interpreted as an error code.
While loop executes command or multiple comands in cycles when the condition exit status is zero.
Before every cycle, while loop checks if the condition returns 0.

while condition
do
    command
done

Since true command always returns zero, while loop will run command in cycles indefinitely.
You can try this in terminal, run true then echo $?
echo $? prints returns status of the previous command

true echo $?
You will see it is 0

You can also try with false

false echo $? 1
False always returns 1.

Now back to the commands that are run in loop.
ukuu --notify Ubuntu Kernel Update Utility checks for kernel updates and notifies if there is one.
sleep 50h - yes it sleeps for 50 hours :alarm_clock:
So it check for new kernels every 50 hours.

Why are both commands in one line?
Semicolon ; is a special character that permits putting two or more commands on the same line.
; executes the right-hand command of ; always regardless whether the previous command succeeded or failed.

Both command will run in your case even if the first command fails.
A; B Run A and then B, regardless of success of A

1 Like

Thanks.

The Gui for Ukuu does not let you set it above 50 hrs.

Was wondering if I could change the script to say 100 hrs. ??

Have you tried setting it to 100?

sleep 300s while true do ukuu --notify ; sleep 100h done

Will try and see what happens.

Just in case, if there’s a limit to the number (but I don’t think there would), you can also use “d” for days instead of “h”.

I changed it to 100 hrs but Ukuu changed it back to 50. :slight_smile: