Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Any way to allow clobbering empty files when noclobber is set?

Hi there,

I switched from tcsh to zsh a while ago (many years too late, I know), and
found zsh can do pretty much everything better. There's one thing I rather
miss though: the 'notempty' option in 'noclobber'. To quote tcsh(1):

> If the shell variable noclobber is set, then the file must not exist or be
> a character special file [...] If notempty is given in noclobber, `>' is
> allowed on empty files; if ask is set, an interacive confirmation is
> presented, rather than an error.

1. Is there any way to do this in zsh (especially the notempty option)? I
   know you can use >! to override it, but empty files are rarely important
   so just allowing them to be clobbered seems better UX in most cases.
   I can't find anything in zshall(1) or the interwebz.

2. Assuming the answer to 1) is "no", would any patches be accepted to add a
   setting for this? I rather miss this behaviour (I actually added these
   settings to tcsh a few years ago).

For context, the most common case (for me, anyway) is when I accidentally
create a file with a failing command:

    $ cmd -wrong-flag > foo
    stderr: you made a mistake

    # Oops, we used a wrong flag, let's correct it:
    $ cmd -correct-flag > foo
    zsh: file exists: foo

    # Ah, an empty file still got created >_< Need to remove it first, or
    # replace > with >!
    $ rm foo
    $ cmd -correct arg > foo


P.S. The emailing list software told me to email zsh-workers-faq@xxxxxxx for
a FAQ about this list, which is what I did and it came back with:

> FAQ - Frequently asked questions of the zsh-workers@xxxxxxx list.
> None available yet.

Maybe remove that part from the template, as there is no FAQ?

Messages sorted by: Reverse Date, Date, Thread, Author