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 45964
- From: "Martin Tournoij" <martin@xxxxxxxxxx>
- To: "Daniel Shahaf" <d.s@xxxxxxxxxxxxxxxxxx>, "Peter Stephenson" <p.stephenson@xxxxxxxxxxx>
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Thu, 04 Jun 2020 14:31:51 +0800
- Cc: zsh-workers@xxxxxxx
- In-reply-to: <20200604014850.52d241bd@tarpaulin.shahaf.local2>
- 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> <20200604014850.52d241bd@tarpaulin.shahaf.local2>
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 😅
Cheerio,
Martin
Messages sorted by:
Reverse Date,
Date,
Thread,
Author