3 ms·
> Patch does a good job of patching. There is no reason why it should also have the job of being able to run arbitrary scripts. It (patch) is not 'run[ning] ar
by pwg 9y ago
> Patch does a good job of patching. There is no reason why it should also have the job of being able to run arbitrary scripts.
It (patch) is not 'run[ning] arbitrary scripts' (ignoring the fact that the actual 'diff' output file is itself a 'script' in a broad sense).
Early versions of diff used to output 'ed' command scripts that would instruct 'ed' how to change one file into another file.
Rather than re-implement all of 'ed' inside of patch, patch simply was written to call 'ed' over a pipe and feed it the input "diff" (in 'ed' format) and let 'ed' handle interpreting the 'ed' script. This in and of itself makes sense. All the 'ed' code for interpreting 'ed' scripts is in 'ed', and enhancements to 'ed' automatically become available to patch and anyone else that calls 'ed' without having to keep plural code bases synchronized. Note that some of this usage may very well have been developed before shared libraries appeared, so there would have been no easy way to share the same 'ed' library among plural tools when there were no shared libraries.
It just so happens that one of ed's commands is a command to execute an arbitrary program. So a carefully crafted diff file can instruct ed to run a program of your choosing.