Hi there,
I managed to write a script that display its progress like this:
~# cat myscript
echo -en ' Completed\015'
for (( i=0; i<=100; i++ )) do
echo -ne $i'%\015'
# perform some actions
sleep .01
done
echo
~# myscript
100% Completed
~#
I can't show it on this post, but we visually see the percent growing from 0 to 100.
Now, I'd like to do something trickier. While the percent is still growing gently on line one, I'd like to display some results on the next lines, visually, I want to obtain something like this. For example. I launch a myscript at time T:
~$ myscript
At T+1 minut:
~$ myscript
20% completed
Action1
Action2
At T+2 minuts:
~$ myscript
65% completed
Action1
Action2
Action3
Action4
At T+3 minuts:
~$ myscript
100% completed
Action1
Action2
Action3
Action4
Action5
Action6
~$
Is it possible that my script keep modifying the first line (percentage) while echoing ActionX every once in a while?
Thanks for your help.
Santiago
I dont think so because it cant go to the next action until it completes the first.
Thanks chatwizrd,
Can you be more explicit, I don't really understand you. The point is not to do all the actions together but one after the other. After each action is completed, I want to display a certain percentage on line one.
For example, here is a script named icandothat:
~# cat icandothat
action1() { echo 'doing action1...'; sleep 3; }
action2() { echo 'doing action2...'; sleep 5; }
action3() { echo 'doing action3...'; sleep 2; }
echo '0% completed'
action1
echo '30% completed'
action2
echo '80% completed'
action3
echo '100% completed'
Here is the result of this script at different times (left) compared to the result of a so called script icannotdothat (right). The script I would like to be able to write is the script on the right.
T=0
~# icandothat ~# icannotdothat
0% completed 0% completed
doing action1... doing action1...
T=3 seconds
~# icandothat ~# icannotdothat
0% completed 30% completed
doing action1... doing action1...
30% completed doing action2...
doing action2...
T=8 seconds
~# icandothat ~# icannotdothat
0% completed 80% completed
doing action1... doing action1...
30% completed doing action2...
doing action2... doing action3...
80% completed
doing action3...
T=10 seconds
~# icandothat ~# icannotdothat
0% completed 100% completed
doing action1... doing action1...
30% completed doing action2...
doing action2... doing action3...
80% completed ~#
doing action3...
100% completed
~#