-
Notifications
You must be signed in to change notification settings - Fork 9
/
shell-temp
37 lines (32 loc) · 1.01 KB
/
shell-temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh -efu
### This file is covered by the GNU General Public License,
### which should be included with libshell as the file LICENSE.
### All copyright information are listed in the COPYING.
if [ -z "${__included_shell_temp-}" ]; then
__included_shell_temp=1
. shell-error
. shell-signal
__shell_clean_temp=0
__shell_clean_temp()
{
local i=0 temp=
while [ $i -lt ${__shell_clean_temp:-0} ]; do
eval "temp=\"\$__shell_clean_temp_$i\""
rm $verbose -rf -- "$temp"
i=$(($i + 1))
done
}
### Usage: create_temporary ret [mktemp options]
create_temporary()
{
local __create_temporary_out __create_temporary_var="$1"
shift
[ "$#" != 0 ] || set -- -dt
__create_temporary_out="$(mktemp "$@" "$PROG.XXXXXXXXX")"
eval "__shell_clean_temp_$__shell_clean_temp=\"\$__create_temporary_out\""
[ "$__shell_clean_temp" != 0 ] ||
signal_handler __shell_clean_temp EXIT HUP PIPE INT QUIT TERM
__shell_clean_temp=$(($__shell_clean_temp + 1))
eval "$__create_temporary_var=\"\$__create_temporary_out\""
}
fi #__included_shell_temp