Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Are there any legitimate reasons to have a particular file both as an input to a pipe and as an output? I wonder whether a shell could automatically “sponge” the pipe’s output if it detected that happening.


The shell can't detect that unless the file is also used as input via `<`. So it couldn't do that in HellsMaddy's example, since the filename is given as an arg to awk instead of being connected to its stdin.


And detecting that would actually implement move semantics in the shell.

Isn’t there already a project to bring Rust to the shell?


Yeah, it seems like the kind of command that you only need because of a quirk in how the underlying system happens to work. Not something that should pollute the logic of the command, imo. I would expect a copy-on-write filesystem to be able to do this automatically for free.


> I would expect a copy-on-write filesystem to be able to do this automatically for free.

this is an artifact of how handles work (in relation to concurrency), not the filesystem.

copy-on-write still guarantees a consistent view of the data, so if you write on one handle you're going to clobber the data on the other, because that's what's in the file.

what you really want is an operator which says "I want this handle to point to the original snapshot of this data even if it's changed in the meantime", which a CoW filesystem could do, but you'd need some additional semantics here (different access-mode flag?) which isn't trivially granted just by using a CoW filesystem underneath.


Do people really use copy-on-write filesystems though? I mean it'd be great if that were a default, but I rarely encounter them, and when I do, it's only because someone intentionally set it up that way. In 30+ years of using Unix systems, I can't even definitively recall one of them having a copy-on-write filesystem in place. Which is insane considering I used VAX/VMS systems before that and it was standard there.


FreeBSD uses ZFS by default, which is copy on write post-snapshot.


That's what I get for living in Linuxland for so long. BSDs tend to be so much smarter, but I'm stuck with Linux inertia.


So, use zfs on Linux.


I thought UFS was still the default with ZFS being a supported alternative option for root filesystems?


Huh? Btrfs is copy on write and it's definitely being used.


sed --in-place has one file as both input and output. It's not really different from any pipe of commands where the input and output files are the same. But sed also makes a copy of the file before overwriting it - per default.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: