help-bash
[Top][All Lists]
Advanced

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

Re: [Question] Reliable way to clean up a directory in EXIT trap


From: Masahiro Yamada
Subject: Re: [Question] Reliable way to clean up a directory in EXIT trap
Date: Tue, 19 Jul 2022 18:02:35 +0900

Here is even simpler test code.


The EXIT handler missed to clean up the tmp file.







masahiro@grover:/tmp/foo$ ls -a
.  ..  test2.sh  test.sh
masahiro@grover:/tmp/foo$ cat test2.sh
#!/bin/bash
set -e

TMP=.tmp_$$

trap "rm -f $TMP" EXIT

touch $TMP

masahiro@grover:/tmp/foo$ cat test.sh
#!/bin/bash

i=0

while [ $i -lt 1000 ]; do
./test2.sh
i=$(( i + 1 ))
done
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ./test.sh
^C^C
masahiro@grover:/tmp/foo$ ./test.sh
^C^C
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ./test.sh
^C
masahiro@grover:/tmp/foo$ ls -a
.  ..  test2.sh  test.sh  .tmp_2859384  .tmp_2863141



-- 
Best Regards
Masahiro Yamada



reply via email to

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