4 ms·
Thanks, I know `||` in general--I meant I hadn't seen the specific construction GP had used. The error handling to delete the output file in case the command fa
by deafbybeheading 12y ago
Thanks, I know `||` in general--I meant I hadn't seen the specific construction GP had used. The error handling to delete the output file in case the command failed is really elegant.
- peff 12y agoIt's actually a little dangerous; what happens when you hit "^C" and the process dies before getting a chance to clean up? It's safer to do: some_cmd >foo.tmp && mv foo.tmp foo The mv will do an atomic rename(), so that you either get the fully formed contents, or nothing at all.
- deafbybeheading 12y agoOnly if you interrupt the actual `rm`, no? If you interrupt the main command, you won't get a 0 exit code so the `||` branch still executes. Your mechanism is clearly safer, but the user is required to clean up `foo.tmp` themselves in case of failure, so it's not really comparable.