LDP/LDP/guide/docbook/abs-guide/seconds.sh

28 lines
483 B
Bash

#!/bin/bash
TIME_LIMIT=10
INTERVAL=1
echo
echo "Hit Control-C to exit before $TIME_LIMIT seconds."
echo
while [ "$SECONDS" -le "$TIME_LIMIT" ]
do # $SECONDS is an internal shell variable.
if [ "$SECONDS" -eq 1 ]
then
units=second
else
units=seconds
fi
echo "This script has been running $SECONDS $units."
# On a slow or overburdened machine, the script may skip a count
#+ every once in a while.
sleep $INTERVAL
done
echo -e "\a" # Beep!
exit 0