Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

option for guaranteed auto cleanup using file descriptor trick #10

@timotheecour

Description

@timotheecour

this answer uses a nice trick to guarantee auto cleanup:

tmpfile=$(mktemp /tmp/abc-script.XXXXXX)
exec 3>"$tmpfile"
rm "$tmpfile"
: ...
echo foo >&3

the cleanup would happen even if a crash happens (or, say, a quit):

When it gets closed (which the kernel does automatically when the process exits) the filesystem deletes the file

the same trick could be used (as option!) in tempfile API

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions