Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

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.

share|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 :) –  José Mélançon Feb 7 '12 at 5:43
add comment

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

 tail -f filename | parallel eval "{}"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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