A NOTE has been added to this issue. ====================================================================== https://austingroupbugs.net/view.php?id=1616 ====================================================================== Reported By: illiliti Assigned To: ====================================================================== Project: Issue 8 drafts Issue ID: 1616 Category: Shell and Utilities Type: Enhancement Request Severity: Editorial Priority: normal Status: New Name: Mark Lundblad Organization: User Reference: Section: Shell and Utilities Page Number: - Line Number: - Final Accepted Text: ====================================================================== Date Submitted: 2022-11-08 23:03 UTC Last Modified: 2023-02-22 13:30 UTC ====================================================================== Summary: Standardize mktemp utility ======================================================================
---------------------------------------------------------------------- (0006166) ormaaj (reporter) - 2023-02-22 13:30 https://austingroupbugs.net/view.php?id=1616#c6166 ---------------------------------------------------------------------- Here's a few more data points. The uutils mktemp is basically same as coreutils, as expected: (ins)root 5 (7104) 0 ~ # uu-mktemp --help create a temporary file or directory. Usage: uu-mktemp [OPTION]... [TEMPLATE] Arguments: [template] Options: -d, --directory Make a directory instead of a file -u, --dry-run do not create anything; merely print a name (unsafe) -q, --quiet Fail silently if an error occurs. --suffix <SUFFIX> append SUFFIX to TEMPLATE; SUFFIX must not contain a path separator. This option is implied if TEMPLATE does not end with X. -p, --tmpdir [<DIR>] interpret TEMPLATE relative to DIR; if DIR is not specified, use $TMPDIR ($TMP on windows) if set, else /tmp. With this option, TEMPLATE must not be an absolute name; unlike with -t, TEMPLATE may contain slashes, but mktemp creates only the final component -t Generate a template (using the supplied prefix and TMPDIR (TMP on windows) if set) to create a filename template [deprecated] -h, --help Print help information -V, --version Print version information Bash's "example" loadable mktemp: (ins)root 5 (7104) 0 ~ # bash -c 'enable -f mktemp{,}; type mktemp; help mktemp' mktemp is a shell builtin mktemp: mktemp [-d] [-q] [-t prefix] [-u] [-v varname] [template] ... Make unique temporary file name Take each supplied filename template and overwrite a portion of it to create a filename, which is unique and may be used by the calling script. TEMPLATE is a string ending in some number of 'X's. If TEMPLATE is not supplied, shtmp.XXXXXX is used and $TMPDIR is used as the name of the containing directory. Files are created u+rw; directories are created u+rwx. Options, if supplied, have the following meanings: -d Create a directory instead of a file -q Do not print error messages about file creation failure -t PREFIX Use PREFIX as the directory in which to create files -u Do not create anything; simply print a name -v VAR Store the generated name into shell variable VAR Any PREFIX supplied with -t is ignored if TEMPLATE is supplied. The return status is true if the file or directory was created successfully; false if an error occurs or VAR is invalid or readonly. And the AST libcmd builtin under ksh93: (ins)root 5 (7104) 0 ~ # ksh93v -c 'builtin mktemp; type mktemp; mktemp --man' mktemp is a shell builtin NAME mktemp - make temporary file or directory SYNOPSIS mktemp [ options ] [ prefix [ directory ] ] DESCRIPTION mktemp creates a temporary file with optional base name prefix prefix. If prefix is omitted then tmp is used and --tmp is implied. A consecutive string of trailing X's in prefix is replaced by a pseudorandom combination of [0-9a-zA-Z]characters, otherwise the first 5 characters of prefix is catenated with a pseudorandom string to construct a file name component of 14 characters. If directory is specified or if prefix contains a directory prefix then that directory overrides any of the directories described below. A temporary file will have mode rw------- and a temporary directory will have mode rwx------, subject to umask(1). Generated paths have these attributes: * Lower case to avoid clashes on case ignorant filesystems. * Pseudo-random part to deter denial of service attacks. * Default pseudo-random part (no specific X... template) formatted to accomodate 8.3 filesystems. A consecutive trailing sequence of X's in prefix is replaced by the pseudo-random part. If there are no X's then the pseudo-random part is appended to the prefix. OPTIONS -d, --directory Create a directory instead of a regular file. -m, --mode=mode Set the mode of the created temporary to mode. mode is symbolic or octal mode as in chmod(1). Relative modes assume an initial mode of u=rwx. -p, --default=directory Use directory if the TMPDIR environment variable is not defined. Implies --tmp. -q, --quiet Suppress file and directory error diagnostics. -R, --regress=seed The pseudo random generator is seeded with seed instead of process/system specific transient data. Use for testing only. A seed of 0 is silently changed to 1. -t, --tmp|temporary-directory Create a path rooted in a temporary directory. -u, --unsafe|dry-run Check for file/directory existence but do not create. Use this for testing only. SEE ALSO mkdir(1), pathtemp(3), mktemp(3) IMPLEMENTATION version mktemp (AT&T Research) 2012-12-12 author Glenn Fowler <[email protected]> author David Korn <[email protected]> copyright Copyright (c) 1992-2015 AT&T Intellectual Property license http://www.eclipse.org/org/documents/epl-v10.html In addition ksh93 has the `>;word` redirect which opens a temporary file and renames it to word if the command returned success. It can serve a similar purpose. The canonical method I thought everyone knew is m4's mkstemp ( https://mywiki.wooledge.org/BashFAQ/062#Using_m4 ) Another reasonably widely-available tool - xfs_io from xfsprogs - can be used to open a file with O_TMPFILE. It works on several platforms including with some non-xfs filesystems. Issue History Date Modified Username Field Change ====================================================================== 2022-11-08 23:03 illiliti New Issue 2022-11-08 23:03 illiliti Name => Mark Lundblad 2022-11-08 23:03 illiliti Section => Shell and Utilities 2022-11-08 23:03 illiliti Page Number => - 2022-11-08 23:03 illiliti Line Number => - 2022-11-08 23:30 steffen Note Added: 0006038 2022-11-09 13:18 illiliti Note Added: 0006041 2023-02-22 13:30 ormaaj Note Added: 0006166 ======================================================================
