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

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

On Thu, Jun 4, 2020, at 09:48, Daniel Shahaf wrote:
> However, I wonder whether there are other ways to peel this orange.  For
> example, I don't recall _other_ cases where I might have found the
> proposed behaviour useful — that is, cases where I used «>» to create
> a file, got an error because the file had been created as empty before
> I executed my command, and would have preferred for shell to just
> proceed without flagging an error — so, thinking out loud, how about an
> option that does the following:
>     Given «foo > bar», if «foo» was run and exited non-zero and
>     NO_CLOBBER in effect [which implies that «bar» didn't exist before
>     foo was run], check whether «bar» is zero-size and, if so, unlink it.
> ?
> [To be clear, no objection to CLOBBER_EMPTY as posted; just brainstorming
> alternatives.]

The thinking was that it's the "least magical" behaviour I could think of:
if I tell zsh to "NO_CLOBBER" then I'm telling it to "don't make me lose
data when I'm being stupid". I think allowing it to overwrite empty files
fits rather nicely with the intent of NO_CLOBBER.

This seems less magic to me than "> creates a file, except when [...]".

That being said, you solution would obviously also be workable, and don't
overly care one way or the other, but this was my thinking behind it.

Also, I'm almost disappointed Peter wrote a patch already, as I was looking
forward to doing it myself heh 😅


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