Removing created temp files in unexpected bash exit

前端 未结 8 1724
无人及你
无人及你 2021-01-29 21:44

I am creating temporary files from a bash script. I am deleting them at the end of the processing, but since the script is running for quite a long time, if I kill it or simply

8条回答
  •  耶瑟儿~
    2021-01-29 22:31

    I prefer using tempfile which creates a file in /tmp in the safe manner and you do not have to worry about its naming:

    tmp=$(tempfile -s "your_sufix")
    trap "rm -f '$tmp'" exit
    

提交回复
热议问题