Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Any way to allow clobbering empty files when noclobber is set?
- X-seq: zsh-workers 45955
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Thu, 4 Jun 2020 01:48:50 +0000
- Cc: Martin Tournoij <martin@xxxxxxxxxx>, <zsh-workers@xxxxxxx>
- In-reply-to: <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20200603020919eucas1p13e26ebcbb335784d14bfb97b137f385a@eucas1p1.samsung.com> <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local>
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
alternatives.]
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.
Cheers,
Daniel
¹ 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