2 LISTSEP="$(printf '\b')"
4 # Create a temporary file, with its name of the form $1_XXX$2, where XXX is
5 # replaced by an unique string.
6 # $1: prefix, $2: suffix
8 tmp=$(mktemp --suffix="$2" "$1_XXXXXXXXXX" 2> /dev/null)
10 # mktemp failed (unsupported --suffix ?), try unsafe mode
11 tmp=$(mktemp -u "$1_XXXXXXXXXX" 2> /dev/null)
12 if [ -z "$tmp" ]; then
13 # mktemp failed again (doesn't exist ?), try very unsafe mode
14 if [ -z "${mymktemp_seq}" ]; then
15 mymktemp_seq=$(date +%d%H%M%S)
17 tmp="$1_$$x${mymktemp_seq}"
18 mymktemp_seq=$((mymktemp_seq + 1))
21 # create temp file, and exit if it existed before
22 sh -C -c "true > \"${tmp}\"" || exit 1
27 # Add a word to the end of a list (words separated by LISTSEP)
28 # $1: list, $2...: words to add
33 eval content=\"\${$list}\"
35 if [ -z "$content" ]; then
38 content="$content${LISTSEP}$*"
41 eval $list=\"\${content}\"
44 # Set contents of a list (words separated by LISTSEP)
45 # $1: list, $2...: words to set
51 # Get the content of a list: positional parameters ($1, $2, ...) are set to the
54 # usage: eval $(list_get list)
56 printf 'IFS="$LISTSEP"; eval set -- \\$%s; IFS="$SAVEIFS"' "$1"