Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I really like the look of the output of bar

But that script is only used for Input/Output operations.

How can I use it as a replacement for sleep but with visual feedback?

sleep 10
share|improve this question

I couldn't see a way to do this using bar. However you might be interested in these other commands that do the same thing, that might suite your needs better.

Method #1 - Fake it

This method will simply overwrite what's been previously displayed to the screen with a larger progress bar. Simple but effective.

Example, ex.bash:


echo -ne '#####                     (33%)\r'
sleep 1
echo -ne '#############             (66%)\r'
sleep 1
echo -ne '#######################   (100%)\r'
echo -ne '\n'

Method #2 - pipeview

The command pv provides progress bar functionality. You can see more elaborate examples in this article titled: A Unix Utility You Should Know About: Pipe Viewer.

$ pv access.log | gzip > access.log.gz
611MB 0:00:11 [58.3MB/s] [=>      ] 15% ETA 0:00:59

Method #3 - spinner

You can use the following sample code to construct your own "spinner" using a simple loop. Within the loop you could embed whatever commands you like. This code comes from this article, titled: Can I do a spinner in Bash?.


printf ' '
for i in $(seq 3); do
  printf '\b%.1s' "$sp"
  sleep 1
echo ''

Method #4 - dialog

There's a command called dialog which does pretty much what you want. It makes use of graphical dialogs, but they're ncurses based so they'll work in most every terminal and/or script so long as there's support for ncurses. You can see all the dialog documentation on the project's website.


ss of guage


share|improve this answer
About slm's the method #1, a more complete example: progressbar.sh. – Alexandre Apr 19 '15 at 13:37

It seems trivial to implement. The bash function below (bar) below behaves like your bar script (based on the short screencast). It also resizes dynamically with the terminal width (on the next call to bar).


#Helper functions
  local width_height=`stty size`
  echo ${width_height/* /}
  local s=$1
  local n=$2
  for((i=0;i<n; i++)); do echo -n "$s"; done
##The actual function
  local percentage=$1
  local padding=10
  local width=$(echo "scale=0; 0.5 * $(terminal_width)" | bc | cut -d. -f1)
  local equals_n=$(echo "$percentage * $width / 100" | bc | cut -d. -f1)
  local dots_n=$((width - equals_n))

  #ANSI escape sequence magic
  local Esc="\033["
  local up="$Esc""K""$Esc""1A""$Esc""K"

  #Clear the line
  string_times_n ' ' "$width"
  echo -ne "\r"

  #Print the current screen
  printf  "%3s%% [" "$percentage"
    string_times_n '=' "$equals_n"
    string_times_n '.' "$dots_n"
  echo -n "]"

  #Go up unless finished
  if [[ "$percentage" == 100 ]] 
    echo -e "$up"


. bar.sh #Assuming it's saved in bar.sh
bar $percentage

Regular progress example:

for i in {1..10}; do bar $((i*10)); sleep 0.1; done;

Random progress example:

for i in {1..10}; do bar $((i*10)); sleep `echo $RANDOM / 10000|bc`; done;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.