How to create a temporary file with portable shell in a secure way?

前端 未结 3 665
说谎
说谎 2021-02-14 11:32

I want to create a temporary file in POSIX shell (/bin/sh).

I found out that mktemp(1) doens\'t exist on my AIX box, and according to How port

3条回答
  •  無奈伤痛
    2021-02-14 12:30

    You didn't exactly define "secure", but one element of it is probably to clean up after yourself.

    trap "rm -f \"$tmpfile\"" 0 1 2 3 15
    

    You can probably man 3 signal to see if there are other signals that should cause your temp file to be erased. Signal zero means "on a clean exit".

提交回复
热议问题