pintcat

progress - Draws a progress bar in a shell window.

Apr 12th, 2021
493
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. A='*'                                 # draw this for the finished part of the progress bar
  4. E='.'                                 # draw this for the unfinished part of the progress bar
  5. typeset -i V=0
  6. typeset -i LENGTH=100
  7.  
  8. function DRAW()                       # <- Feed me with a number!
  9. {
  10.     BAR="["
  11.     typeset -i ACHIEVED=0
  12.     typeset -i EMPTY=$LENGTH-$1
  13.     while [ $ACHIEVED -lt $1 ]; do    # draw the part finished by the process
  14.     BAR=$BAR$A
  15.     ACHIEVED=$ACHIEVED+1
  16.     done
  17.     while [ $EMPTY -gt 0 ]; do        # draw the unfinished part
  18.     BAR=$BAR$E
  19.     EMPTY=$EMPTY-1
  20.     done
  21.     echo -en "\r$BAR]"
  22. }
  23.  
  24. while [ $V -le 100 ]; do
  25.     DRAW $V
  26.     sleep 0.1s
  27.     V=$V+1
  28. done
  29. echo
  30.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×