Creating temporary files in bash

后端 未结 5 1579
心在旅途
心在旅途 2020-12-02 08:39

Are there objectively better ways to create temporary files in bash scripts?

I normally just name them whatever comes to my mind, such as tempfile-123, since it will

5条回答
  •  余生分开走
    2020-12-02 09:41

    You might want to look at mktemp

    The mktemp utility takes the given filename template and overwrites a portion of it to create a unique filename. The template may be any filename with some number of 'Xs' appended to it, for example /tmp/tfile.XXXXXXXXXX. The trailing 'Xs' are replaced with a combination of the current process number and random letters.

    For more details: man mktemp

提交回复
热议问题