Specifically in the case of
cat x y > y and
cat x >> x where x and y are files.
What would happen if I didn't get a "input file is output file" error? Basically, why am I not allowed to run those commands?
cat x y > y would be the same as
cp x y (because
y would have been truncated by the time
cat started) followed by
cat y >> y.
cat x >> x would be an infinite loop until your disk was full or you hit the filesystem's file-size limit (because it keeps adding to the end of the file and then reading it back in to add again).
Note that this "error" doesn't mean that
cat didn't do anything - it's just a notice that this particular file was skipped (in GNU
cat, at least). You're "allowed" to run it, it just probably didn't do what you wanted and it's letting you know.
The test in GNU
cat for generating that message is that:
st_devfield) and inode (
st_inofield) are the same for both the output fd and the input file under examination; and
If all those apply, it prints the diagnostic and moves on to the next input file.
Some versions of the
cat command don't make this check and you can make these things happen. I can imagine a system where they do make the check and it's not able to tell they're the same file as well, though I couldn't off-hand tell you of one. In either case, it probably ends badly. It's possible that, rather than a loop, you just end up with the file so far doubled, if the
cat implementation only makes a single write of the entire memory-mapped file, but that's just a lesser kind of badly.