[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] [PATCH] Use bash for several contrib scripts
From: |
Daode |
Subject: |
Re: [Groff] [PATCH] Use bash for several contrib scripts |
Date: |
Fri, 03 Jan 2014 17:11:34 +0100 |
User-agent: |
s-nail v14.5.1-31-gb21bafe |
Doug McIlroy <address@hidden> wrote:
|I must be missing something in the discussion about random
|numbers. Why does groff need them? In the offered example
| tmp="$d/eqn2graph$groff_rand"
|the "random number" serves only to make a (supposedly) unique
|name. But of course, if the number is truly random, it is not
|guaranteed to be unique. Why does groff not use the time-honored
|$$ to serve the purpose? The only requirement for an absolute
|guarantee of uniqueness is that the shell script whose pid $$
|represents lives as long as the temporary file.
POSIX also loomed some notes on temporary files in the shell [1]:
Having a function like tmpnam( ) in the ISO C standard is
important in many high-level languages. The shell programming
language, however, has built-in string manipulation facilities,
making it very easy to construct temporary filenames. The names
needed obviously depend on the application, but are frequently
of a form similar to:
$TMPDIR/application_abbreviation$$.suffix
In cases where there is likely to be contention for a given
suffix, a simple shell for or while loop can be used with the
shell noclobber option to create a file without risk of
collisions, as long as applications trying to use the same
filename name space are cooperating on the use of files after
they have been created.
[1] <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pathchk.html>
--steffen