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

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

Peter Stephenson wrote on Wed, 03 Jun 2020 12:04 +0000:
> Martin Tournoij wrote:
> > 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'.  
> This isn't actually hard to implement.  What does everyone else think?

I certainly have several cases in my $HISTFILE where I repeated
a command with «>» changed to «>!»,¹ in the pattern Martin described.

I suppose that pattern is common enough to offset the standard "Not
another option!" concern.

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

Peter Stephenson wrote on Wed, 03 Jun 2020 12:04 +0000:
> +++ b/Doc/Zsh/options.yo
> @@ -1168,6 +1168,19 @@ If the option is not set, and the option tt(APPEND_CREATE) is also
> +item(tt(CLOBBER_EMPTY))(
> +This option is only used if the option tt(CLOBBER) is not set: note that
> +it is set by default.

The referent of the pronoun "it" is ambiguous.



¹ The first five of them [I didn't check further] are a pretty varied
  bunch: some of them are a single simple command with an output
  redirection; some of them have the redirection inside a function [or
  a «strace zsh -c»]; and one of them uses the $NULLCMD syntax with
  literally nothing on the line other than the redirection operator and
  its file target.

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