Suppose you run some script such as a perl or tcl. For example, $ ./script.sh; ./script.pl;  source script.tcl. It takes some time to get executed and return to prompt. How to display the percentage of execution meanwhile the execution?Below you can find an example UI. It displays the execution time taken for the script at the end.1% Completed the exectuion of script.pl2% Completed the exectuion of script.pl. . . .100% Completed the the exectuion of script.plEx: Execution time for script.pl is :50 Seconds
How to show the percentage progress of script execution in Unix?
scripting
The following script shows:  Current item (iteration) number  Sliding window average rate (eg. average over 10 iterations)  Overall average rate  The percentage progressed so far (if the number of irrigation is known)  The output:  317:  window: 3.76/s   overall: 3.28/s   progress: 31.7%The test file:  set test_file# create a test filefor i in {1..1000} ;do echo $i; done >$1The script:  if=$1             # the input filelct=$(wc -l <$if) # number of lines in input filetot=${lct:-0}       # total number of itterations; If unknown, default is 0                    #+  The total is know in this case. '$tot' is just a rough                     #+  example of how to suppress the progress %age outputbeg=$(date +%s.%N)  # starting unix time.%N is nanoseconds (a GNU extension)swx=10              # keep a sliding window of max 'n' itteratons (to average)unset sw            # an array of the last '$swx' ratesfor i in $(seq 1 $lct) ;do    sw[$i]=$(date +%s.%N)  # sliding window start time    # ================                         sleep .$RANDOM       #  ... process something here    # ================    now=$(date +%s.%N)     # current unix time    if ((i<=swx)) ;then        sw1=1              # first element of sliding window          sww=$i             # sliding window width (starts from 1)    else        sw1=$((i-swx+1))        sww=$swx            fi    bc=($(bc <<<scale=2; $i/($now-$beg); $sww/($now-${sw[$sw1]})))    oavg=${bc[0]}                  # overall average rate    swhz=${bc[1]}                  # sliding window rate    ((i>swx)) && unset sw[$sw1-1]  # remove old entry from sliding window list    ((tot==0)) && pc= || pc=progress: $(bc <<<scale=1; x=($i*100)/$tot; if (x<1) print 0; x)%    msg=$i:  window: $swhz/s   overall: $oavg/s   $pc    printf \r%$((${#i}+1))s=\r%s  $msgdone