- THIS="$1"
- FIRST="$2"
- LAST="$3"
- RANGE="$(($LAST - $FIRST))"
- PROG="$(($THIS - $FIRST))"
- # this automatically rounds to nearest integer
- PERC="$(((100 * $PROG) / $RANGE))"
- # note \r so next update will overwrite
- printf "%3d%%\r" $PERC
+ test -t 1 || return 0 # supress progress meter if non-interactive
+ THIS="$1"
+ FIRST="$2"
+ LAST="$3"
+ RANGE="$(expr $LAST - $FIRST ||:)"
+ PROG="$(expr $THIS - $FIRST ||:)"
+ # this automatically rounds to nearest integer
+ PERC="$(expr 100 \* $PROG / $RANGE ||:)"
+ # note \r so next update will overwrite
+ printf "%3d%%\r" $PERC