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

    set -o noclobber
... works wonders to avoid this.

Sure, one may have to think and replace instances of:

    foo > bar
with:

    foo | tee bar >/dev/null
or:

    rm -f bar ; foo > bar
... but the times the "noclobber" option has _helped_ me more than makes up for the times it's been a nuisance.



And to undo this in the current shell, because of said nuisance:

set +o noclobber

For some reason this is hard for me to remember, because of what the + and - signs have come to symbolize in more recent UI. set +o seems really backward to me, and unset, surprisingly, does not work.

I've commented this line out in all my .rc, because I've found it to be a nuisance without having bought me much. The better principle is do careful work as root, and don't give careless or junior people root. My root PS1 very 'l33t', look and despair:

export PS1="[\[\e[01:31m\u@h\[\e[m\] \W]# "


From the zsh manpage:

    >| word
    >! word
           Same as >, except that the file is truncated to 
           zero length if it exists, even if CLOBBER is unset.
Note: If you're a bash user the >| syntax is available, but not >!.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: