Need to pause execution in Bash? Follow these easy steps:
1. Basic Sleep Command:
sleep command followed by the number of seconds to pause:
#!/bin/bash
echo "Start"
sleep 5
echo "End after 5 seconds"
2. Sleep for Minutes:
m to specify minutes:
#!/bin/bash
echo "Start"
sleep 2m
echo "End after 2 minutes"
3. Sleep for Hours:
h to specify hours:
#!/bin/bash
echo "Start"
sleep 1h
echo "End after 1 hour"
4. Sleep for Days:
d to specify days:
#!/bin/bash
echo "Start"
sleep 1d
echo "End after 1 day"
5. Sleep with Fractions of a Second:
#!/bin/bash
echo "Start"
sleep 0.5
echo "End after 0.5 seconds"
Jorge García
Fullstack developer