#!/bin/bash # Check bin/udt-machine-name: quoting round-trips through shlex, other keys # survive, a second set replaces rather than appends. # Copyright (C) 2026 Danilo M. # Licensed under the GNU General Public License v2 only. set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT export UDT_MACHINE_INFO="$tmp/machine-info" printf 'ICON_NAME=computer\nPRETTY_HOSTNAME="old"\n' > "$UDT_MACHINE_INFO" "$repo/bin/udt-machine-name" 'first' >/dev/null "$repo/bin/udt-machine-name" 'Anne'"'"'s "Box" \ $HOME' >/dev/null [ "$(grep -c '^PRETTY_HOSTNAME=' "$UDT_MACHINE_INFO")" = 1 ] grep -qx 'ICON_NAME=computer' "$UDT_MACHINE_INFO" python3 - "$UDT_MACHINE_INFO" <<'PY' import shlex, sys line = next(l for l in open(sys.argv[1]) if l.startswith("PRETTY_HOSTNAME=")) got = " ".join(shlex.split(line[len("PRETTY_HOSTNAME="):])) assert got == 'Anne\'s "Box" \\ $HOME', got PY ! "$repo/bin/udt-machine-name" $'a\nb' 2>/dev/null ! "$repo/bin/udt-machine-name" '' 2>/dev/null echo "machine-name OK"