Skip to content
Advertisement

How to put an executable script on the background and wake it up after x minutes

I’m developing a timer in bash and this is what I’ve come up with so far:

#!/bin/bash

echo -n "For how long should I sleep? "
read answer
minutes=$((answer * 60))
sleep $answer && echo foo

It works like I was expecting except that I have to wait the X minutes I passed as input to get the prompt back.

Any ideas how I can execute this and have it execute it in the background so I can keep working with my terminal without waiting for script to finish?

Advertisement

Answer

Just add an & to the end of last line. That is:

sleep $answer && echo foo &
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement