Hacker Newsnew | comments | ask | jobs | submitlogin
pwg 587 days ago | link | parent

> 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.



gnosis 586 days ago | link

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

-----

Evbn 587 days ago | link

But it's obnoxiously not set by default.

-----

sequoia 586 days ago | link

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.

-----




Lists | RSS | Bookmarklet | Guidelines | FAQ | DMCA | News News | Feature Requests | Bugs | Y Combinator | Apply | Library

Search: