Reputation: 19
Kind of suck at bash here. Looking for help. I'm trying to write a script that takes an int argument, and sleeps for 10 * argument seconds, then displays the current date and time.
I also want an infinite loop, and a message to echo when it is ctrl c'd out of.
Here's what I've got so far:
#!/bin/bash
trap "echo I'm done here && exit" INT
time=10*$1
now="$(date)"
while :
do
sleep "$time"
echo ""
echo "Current date and time: $now"
done
Upvotes: 1
Views: 380
Reputation: 184965
#!/bin/bash
trap "echo \"I'm done here\" && exit" INT
if [[ ! $1 ]]; then # check @triplee comment below
echo >&2 "Missing arg 1"
exit 1
fi
while true; do
sleep $((10 * $1))
echo "Current date and time: $(date)"
done
Check http://mywiki.wooledge.org/ArithmeticExpression
And check what @JNevill said in comments upper
Upvotes: 1