Hi.
This illustrates one interesting characteristic of processes. Here is my understanding: the script does not
directly substitute file ed_script for STDIN for the ed command. Since "< ed_script" is unprotected from the shell, it re-directs for
this process, the
find process. The child process in which
ed runs will inherit this re-direction and can be read once. After that, an EOF is encountered for subsequent reads.
There are a number of solutions. You can place the ed and the re-direct into a second script, omitting any mention of re-direction in the script in which find is located, and calling the new script in the exec portion of the
find.
Another solution would be to protect the command
ed <ed_script with quotes, but then you would need to use
eval to re-scan it. However, a further complication arises because
eval is not an external command, it is a shell builtin. That means that you would need to call
bash explicitly, like:
Code:
find d1 -name 't?' -exec bash -c "eval ed {} <ed_script" \;
One slight drawback to ed is that you will see the character counts for reading and writing when you edit the file.
You don't need to use
sed in place of
ed, but I tend to use sed. It has an extra complication in that it will require you to use in-place editing in sed, or re-copy the output stream over the source file. I recommend you work on copies of your important files while getting any of these solutions running.
I've tested all of these for this problem (except sed, which is fairly straight-forward).
You could also investigate opening and closing STDIN, but I did not look at that, because you'd probably do that in a script, and. if you're going to write a script, you might as well use the simplest solution.
As an aside, the
find command has some interesting features and uses; see
http://amitsharma.linuxbloggers.com/how_to_find.htm for an good tutorial with examples.
Best wishes ... cheers, makyo