I'm actually looking for a bash script who monitor a file, execute each new line in the file and then remove the line. When all the file is processed, the script mush wait for new lines.

I searched for any answers but barely found anything more than reading each line in a file.

By the way, is bash efficient at a task like this or should I build a little C program to do this?

link|improve this question
feedback

2 Answers

up vote 0 down vote accepted

The following does everything you ask except for removing the lines from the file:

$ ./script && tail -n0 -f script | while read line; do eval "${line}"; done;

First, just execute the file and then abusing tail and eval you can quite easily approximate the behavior you desire.

link|improve this answer
Thanks, since the loop start at the end of the file I can do what I want without removing lines. So this do exactly what I need :) – Karaziox Feb 7 at 5:43
feedback

If removing the line is not a must, you can also try:

 tail -f filename | parallel eval "{}"
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.