Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .