coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Probing suitability for two features: add incremental integer suffix


From: Markus Läll
Subject: Re: Probing suitability for two features: add incremental integer suffix; print created temp file/dir to stderr
Date: Tue, 15 Aug 2023 14:26:32 +0300

Right, I guess for the "numbered tempfile" idea, the thing that I
actually want is to maintain creation order and that can also be
achieved with `ls -t`.

Regarding duplicating tempfile's name to stderr, I do agree that it's
easily recreated in bash. The main issue with it is that written out
inline it breaks flow in the sense that taking up the amount of space
it does, and it's harder to see what the main command does.


On Mon, Aug 14, 2023 at 3:43 PM Pádraig Brady <P@draigbrady.com> wrote:
>
> On 13/08/2023 19:39, Markus Läll wrote:
> > Hi list,
> >
> > my first post here :)
> >
> > As when using mktemp I've often wanted the following features:
> >
> > Instead of a random string, add an incrementing number to the end of
> > the temp file. E.g with `mktemp -n` one would get /tmp/tmp.1,
> > /tmp/tmp.2 and so on. Would this make sense as a feature? (Does this
> > exist in some other commonly available command?) Thus far I've
> > resorted to a while loop in bash[1] which constructs such a numbered
> > file and tests for file existence, returning the first one not found,
> > but this is long to write out. I've also had a bash function for that,
> > but it seems like it would be nice if mktemp had this built in.
>
> A similar request recently was for similar numbered extension for cp --backup
> https://lists.gnu.org/archive/html/coreutils/2023-07/msg00022.html
>
> > The second feature would be to echo the temporary file name into
> > stderr as well. Motivating example would be when running mktemp as
> > part of another command, e.g `tee -a "$(mktemp -e)"` (-e is an
> > invented flag for this functionality), where it would print a line
> > "mktemp: /tmp/tmp.a0vC8d1KIt" to stderr, so that the user would know
> > which file was created. This is useful when a file is temporary but
> > you might still want to inspect it for debugging purposes later on. As
> > with everything, this effect can also be achieved with a longer
> > command[2], but it would more convenient if it were built in. :)
>
> Shell support for redirecting output seems sufficient for this TBH
>
> > [1]
> > mktemp_n() (
> >      BASENAME="$1"
> >      SUFFIX=1
> >      while [ -e "${BASENAME}.${SUFFIX}" ]; do
> >          ((SUFFIX++))
> >      done
> >      echo "${BASENAME}.${SUFFIX}"
> > )
> >
> > [2] mktemp | (echo -n 'mktemp: ' > /dev/stderr && tee /dev/stderr)
>
> cheers,
> Pádraig
>


-- 
Markus Läll



reply via email to

[Prev in Thread] Current Thread [Next in Thread]