Debian Codegraph @

progress-bar2.sh

raw symbols SCIP
1 #! /bin/bash
2 # progress-bar2.sh
3 # Author: Graham Ewart (with reformatting by ABS Guide author).
4 # Used in ABS Guide with permission (thanks!).
5
6 # Invoke this script with bash. It doesn't work with sh.
7
8 interval=1
9 long_interval=10
10
11 {
12 trap "exit" SIGUSR1
13 sleep $interval; sleep $interval
14 while true
15 do
16 echo -n '.' # Use dots.
17 sleep $interval
18 done; } & # Start a progress bar as a background process.
19
20 pid=$!
21 trap "echo !; kill -USR1 $pid; wait $pid" EXIT # To handle ^C.
22
23 echo -n 'Long-running process '
24 sleep $long_interval
25 echo ' Finished!'
26
27 kill -USR1 $pid
28 wait $pid # Stop the progress bar.
29 trap EXIT
30
31 exit $?