0

I currently have a loop this way (working perfectly):

while true; do /usr/bin/R_START; sleep 0.1; done 

The script "R_START" uses the lines of a text file named "FILE.TXT", they are deleted as soon as the script executes its instructions. I wonder if it is possible to cause the "R_START" loop to be interrupted when the "FILE.TXT" file is less than 3 lines without the need for Ctrl+C.

My biggest problem is that I need to run other "3 loops" similar to this, but I am "forced" to give Ctrl+C so I can execute the next loop.

Here's an example of what I have to do manually: Firstly I execute:

while true; do /usr/bin/R_START; sleep 0.1; done

It shows some error messages when there are no more than 3 lines in the FILE.TXT file. That's when I give Ctrl+C and continue to execute the next loop:

while true; do /usr/bin/R_20; sleep 0.1; done

It does basically the same as the first loop, and uses the same file "FILE.TXT". I see that it concluded when it shows some error messages when there are no more than 3 lines in the file "FILE.TXT". This is where I give Ctrl+C and continue executing the next loop (the next one in this case will be exactly the same):

It does basically the same as the first loop, and uses the same file "FILE.TXT". I see that it concluded when it shows some error messages when there are no more than 3 lines in the file "FILE.TXT". This is where I give Ctrl+C" and continue executing the next loop (the next one in this case will be exactly the same):

while true; do /usr/bin/R_20; sleep 0.1; done

After it completes (when it shows the same message of all because it does not have more than 3 lines in the file FILE.TXT) I give Ctrl+C and I manually continue to the last loop:

while true; do /usr/bin/R_30; sleep 0.1; done

The last one does exactly the same as the previous ones and I also have to give Ctrl+C after it gives the error message due to not having more than 3 lines in the file "FILE.TXT".

There would be a way to "automate" these loops: R_START, R_20 (2x), and R_30?

Xavier Guihot
  • 54,987
  • 21
  • 291
  • 190
logvca
  • 57
  • 7
  • Please use the common markup - don't invent your own. – user unknown Mar 22 '18 at 09:24
  • Something similar to this? `while [ $(wc -l >FILE.TXT; done` (although I make the file grow instead because it was easier). – Arndt Jonasson Mar 22 '18 at 09:27
  • I'm sorry, I did not quite understand. But the answer to your question is "YES". It would be something similar to this command you sent, but I have not been able to implement it yet. Would you have another example? Thank you – logvca Mar 22 '18 at 14:13
  • If you understand my suggestion, it should be easy to adapt it to your needs. Is there any particular detail you want me to explain? – Arndt Jonasson Mar 22 '18 at 14:43
  • I was confused with the command I needed, thank you! It worked perfectly here! – logvca Mar 23 '18 at 00:00
  • Arndt Jonasson, If you can, put your tip that I will mark as the best answer. Thank you. – logvca Apr 29 '18 at 04:28

0 Answers0