utility
mktemp
Create a fresh directory with an unpredictable suffix. Check status and remove only owned fixture contents. Template rules vary.
Formal Syntax & Structure
bash syntaxbash
mktemp -d TEMPLATEParameters & Attributes
| Name | Type | Description |
|---|---|---|
| TEMPLATE | string | Template containing trailing X characters. |
| -d | option | Create a directory. |
Return Value
exit status
Exit status 0 on success; nonzero indicates failure or a command-specific condition. See description and example.
Working Example
Example Snippetbash
work=$(mktemp -d ./bm.XXXXXXXX) || exit 1printf 'temporary\n' > "$work/note.txt"cat -- "$work/note.txt"rm -- "$work/note.txt" && rmdir -- "$work" || exit 1printf 'cleaned\n'