Peng Yu wrote: > Is there a way to overload operators like '>' and '>>' in bash, just > as overloading in C++, etc. Suppose I have already made some bash > program using '>' and '>>' without thinking about symbolic link, but I > begin aware of them later. I would be cumbersome to add a test > statement and deciding whether 'rm' or not for each usage of '>' and > '>>'.
It sounds to me like you are trying to implement a "script space" version of copy-on-write semantics? Perhaps you should investigate using one of the filesystem based solutions. It would probably give you a better result. > A more general question is how to change the behavior of a program > (for example compiled from C code) to delete symbolic link and write a > new file, without recompiling the program. A Comment: Symbolic links are designed to be transparent. Normal programs are not aware of them. You could probably create an LD_PRELOAD library to intercept file modification calls and then handle them in your own code. But I think it would be difficult to do it all completely correctly and not to introduce bugs. I advise against it. Bob