Fill effect in a shell script
Good morning everyone..
It's a wierd question, but I am curious about it. Let's say I have a script Code:
for i in $file Any opinion is most welcome!! |
As long as <command> doesn't produce any output, you can do some basic "animation" with carriage return "\r". This is a special character that moves the cursor the beginning of the line, so you can then overwrite the previous contents:
Code:
blink=0 Code:
#!/bin/bash |
Thanks, but how can I impliment this code in my script? My test script is:
Code:
for i in $file Could you show me the way by modifying my script? Thanks a lot again! |
You can put the blinking loop in the background:
Code:
#!/bin/bash |
i heard them referred to as spinners. this is my favorite spinner design:
Code:
frames=('\__' '_|_' '__/' '_|_') |
Quote:
Is there any way that same thing can be done with same type of symbols? I mean somthing like this: .(wait some mili seconds).(wait).(wait)... Then again first .(wait) and so on... |
Quote:
Code:
frames=('. ' '.. ' '... ' '....') |
Quote:
In addition to your frames variable, I just added one more empty values as: Code:
frames=(' ' '. ' '.. ' '... ' '....') Thanks a lot Mr. ntubski and many thanks to Mr. schneidz also. |
Termination of a function in shell script
Following is my final script:
Code:
#!/bin/bash Problem 1# In output of the script, it gives me an error, Quote:
Problem 2# If I want to stop the script in between processing using CTRL+C, it's not working and function is keep going on. One way is to kill script's PID, which I don't want. So what's a safe way to stop the script if I want to? |
I haven't been able to recreate your #1 issue yet, but you might do this to suppress the message with the following modification.
Code:
kill $blinker_pid 2>/dev/null - Raj |
Quote:
Meanwhile, I put a exit 0 just as: Code:
.... But now my question is, how to terminate a script in between processing, I mean beofore it gets finished? |
Try this.. What the trap command does is it traps the SIGINT signal and passes control to the control_c function.
Code:
#!/bin/bash - Raj |
The "terminated" message doesn't come directly from the kill command but from the shell when it sees a child process that exited due to a signal. You need to insert this line at the top of the blinker() function:
Code:
trap "exit 0" TERM |
Thank agian Raj. The trap cmd worked fine. I was also awere about this, but I was not sure how to use it this way. You showed me a good way!
|
Quote:
|
All times are GMT -5. The time now is 04:42 PM. |