Reputation: 49
Can we set the timer in shell script? means if I set the timer for 20 secs my shell scripts should be execute like this :
20..19..18..17..
after completing the I should get the result. Is it possible ? Please assist me.
Upvotes: 1
Views: 5579
Reputation:
With for loop it looks like:
#!/bin/bash
for (( i=20; i>0; i-- ))
do
clear
echo -n "$i"
sleep 1
done
Upvotes: 0
Reputation: 212248
It's not entirely clear what you want: if xyz.sh
finishes in 3 seconds, do you want to wait an additional 17 seconds? Or do you want to interrupt xyz.sh after 20 seconds and make it produce output? If the latter:
$ cat a.sh
#!/bin/bash
./xyz.sh &
i=${1-20}
echo
while test $i -gt 0; do printf "\r$((i--))..."; sleep 1; done
kill $!
$ cat xyz.sh
#!/bin/sh
foo() { echo "this program doesn't do much"; }
trap foo TERM
sleep 30 &
wait
Upvotes: 0