Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

sleep 10
share|improve this question
add comment

1 Answer

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:

#!/bin/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?.

#!/bin/bash

sp='/-\|'
printf ' '
for i in $(seq 3); do
  printf '\b%.1s' "$sp"
  sp=${sp#?}${sp%???}
  sleep 1
done
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.

screenshot

ss of guage

References

share|improve this answer
add comment

Your Answer

 
discard

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.