Subject: Re: touch(1) enchancement, mkstemp(1)
To: Darren Reed <>
From: J.T. Conklin <jtc@NetBSD.ORG>
List: current-users
Date: 02/10/1998 21:22:08
Darren Reed <> writes:
> I'd like to propose an extension to touch(1) that returns information
> about whether the file being touch'd actually existed prior to touch
> being executed.  Something like an option causing it to return -1
> if EEXIST when opening with O_EXCL|O_CREAT.

What would this give you that ``test -e foo'' does not?  I'd hate to
have us start adding various new knobs to shell utilities --- people
might use them.  I can allready hear the whining ``but it works on 

> I'd also like to propose that a command line interface to mkstemp(3)
> be implemented.  It would work something like this:
> prog=`basename $0`
> tmpfile=`mkstemp /tmp/${prog}.XXXXXX`
> where tmpfile is the resulting filename (i.e. X's are changed to
> something else).  mkstemp(1) would return 0 on success and 1 if
> it failed to create a file.

For temporary files in shell scripts, does it matter what name is
given to the file?  Perhaps there is a way to create a unlinked 
temp file and refer to it by file descriptor.

Perhaps something like:
	exec tmpfile 4<>
	echo "foo" 1>&4 
	echo "bar" 1>&4
	cat 0<&4

Where tmpfile creates a file with file descriptor 4 and then unlinks
the file (I haven't tried this myself, but I have used bits and pieces
like this in shell scripts in the past.