LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-25-2003, 06:07 PM   #1
apeekaboo
Member
 
Registered: Apr 2003
Location: Stockholm/Sweden
Distribution: Kubuntu, Debian, Slax
Posts: 91

Rep: Reputation: 16
bash: How can I create a progress indicator?


Something that has puzzled me for quite som time now is how I could create a progress indicator in bash.
You know when you're executing a long-running command and the command prints out dots, or a rotating dash, to show you that it's still working.

I was thinking about something like this:
Code:
echo -n "Working"

while (downloading a file or maybe searching for a file); do
    echo -n "."
    sleep 1
done

echo " Done"
The above example would not work since the command is performed and if it succeeds then echo a dot, sleep for one second and return to the beginning of the loop and run the command again...

I've also tried with a variable and a function run in the background.
When the function is finished it would change the variable and this would cause the loop to finnish, but this didn't work either...

Does anyone have a working solution for this?
Thanks in advance!
 
Old 06-25-2003, 06:39 PM   #2
apeekaboo
Member
 
Registered: Apr 2003
Location: Stockholm/Sweden
Distribution: Kubuntu, Debian, Slax
Posts: 91

Original Poster
Rep: Reputation: 16
Solved it with some help from another forum.
I'll leave this post in case someone else is interested.

The final code:
Code:
searchfor="xmms"                # something to search for
tempfile="/tmp/search.log"      # temporary logfile


echo -n "Searching for $searchfor"

# execute the command
# send errors to /dev/null
# send output to logfile
find / -name $searchfor 2>/dev/null 1>>$tempfile &

#  echo dots while command is executing
while ps |grep $! &>/dev/null; do
        echo -n "."
        sleep 2
done

echo " Done"

echo "Result:"
cat $tempfile

rm $tempfile
 
1 members found this post helpful.
Old 06-27-2003, 03:11 AM   #3
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
This looks very cool. Where would I place this code?

-twantrd
 
Old 06-27-2003, 05:11 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,378

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
what do you mean where? that's a complete example there...
 
Old 06-27-2003, 10:18 AM   #5
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 46
If you'd like a stationary spinner instead of moving dots:
Code:
#!/usr/bin/env bash

while [ 1 ]; do
echo -e -n '|\r\c'
echo -e -n '/\r\c'
echo -e -n '-\r\c'
echo -e -n '\\\r\c'
done
Of course, you would want to change the while statement, and the spinner is very fast. . .
 
Old 06-27-2003, 10:41 AM   #6
apeekaboo
Member
 
Registered: Apr 2003
Location: Stockholm/Sweden
Distribution: Kubuntu, Debian, Slax
Posts: 91

Original Poster
Rep: Reputation: 16
Yes, it's a complete example (and a useless one too...)
The idea was just to show how you can get something to look at while the computer is working.
It's not really a progress indicator as much as it's a 'process indicator', showing that the process is still alive.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
md5sum progress indicator Ianmcc Linux - Software 3 02-04-2009 02:50 PM
gui file copy progress indicator? zero79 Linux - Software 3 07-10-2005 02:00 AM
How to create progress bar in Glade skie_knite007 Programming 1 04-22-2005 03:59 PM
Loss of scp progress indicator when piping command to tee Arodef Linux - General 1 03-08-2005 09:01 PM
cp command with progress indicator exodist Linux - Software 1 07-21-2004 06:27 PM


All times are GMT -5. The time now is 08:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration