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
30 local list content newcontent
34 eval content=\"\${$list}\"
38 if [ -z "$content" ]; then
41 content="$content${LISTSEP}$newcontent"
43 eval $list=\"\${content}\"
47 # Like list_add, but only if first word to add ($2) is not empty
48 list_add_not_empty () {
54 # Set contents of a list (words separated by LISTSEP)
55 # $1: list, $2...: words to set
61 # Get the content of a list: positional parameters ($1, $2, ...) are set to the
64 # usage: eval $(list_get list)
66 printf 'IFS="$LISTSEP"; eval set -- \\$%s; IFS="$SAVEIFS"' "$1"