Hacker News new | comments | show | ask | jobs | submit login

> and the fact that `> somefile.txt` will silently truncate the file

Bash has the "set -C" option to toggle on "no-overwrite" mode for redirection operators.




zsh also has a "setopt NO_CLOBBER", but it's also not the default (unfortunately).

Default behavior:

  % touch foo
  % echo bar > foo
  % cat foo
  bar
  % rm foo
No clobber mode:

  % setopt NO_CLOBBER
  % touch foo
  % echo bar > foo
  zsh: file exists: foo
Manual override:

  % echo bar >| foo
  % cat foo
  bar


But it's obnoxiously not set by default.


This might screw up some POSIX shell scripts if they expect to be able to write a tmp file or overwrite one if it already exists.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: