You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
833 B
Bash

#!/bin/bash
# Arbitrary delay
# simpledelay.sh <arg>
# <arg> is an integer value and specifies the delay interval in seconds
minint=0 # mininum delay
maxint=15 # maximum delay
# Check that only one argument has been submitted
if [ $# -eq 1 ]; then
# Check that the argument is an integer and in the valid range
if [ $1 ]; then
if [ ! $(echo "$1" | grep -E "^[0-9]+$") ]; then
echo $1 is not a valid integer.
exit 1
else
if ! [ $1 -ge $minint ] || ! [ $1 -le $maxint ]; then
echo $1 is an invalid value. Range is [$minint-$maxint]
exit 1
fi
fi
fi
else
# No args or more than one submitted
echo "<simpledelay.sh> Not a valid numbers of arguments. Only one argument allowed."
exit 1
fi
# Execute the delay
delaysecs=$1
while [ $delaysecs -gt 0 ]; do
sleep 1 &
delaysecs=$[$delaysecs-1]
wait
done