]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
test(run-qemu): quote arguments only if needed
authorBenjamin Drung <benjamin.drung@canonical.com>
Fri, 31 Oct 2025 12:38:25 +0000 (13:38 +0100)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Fri, 31 Oct 2025 13:28:22 +0000 (09:28 -0400)
Increase the readability of the qemu call log by quoting the arguments
only if needed.

test/run-qemu

index 7e95816cd7b678c239a690cd6de5b0ffb1ce6ac8..073d69b18b1bf32ded99d381e0cf1e7f6bfbee33 100755 (executable)
@@ -7,6 +7,18 @@ export PATH=/usr/sbin:/usr/bin:/sbin:/bin
 ARCH="${ARCH-$(uname -m)}"
 QEMU_CPU="${QEMU_CPU:-max}"
 
+quote_args() {
+    local arg args=()
+    for arg in "$@"; do
+        if [[ -z $arg || $arg =~ [[:space:]\'] ]]; then
+            args+=("'${arg//\'/\'\\\'\'}'")
+        else
+            args+=("$arg")
+        fi
+    done
+    echo "${args[*]}"
+}
+
 set_vmlinux_env() {
     if [[ ${KVERSION-} ]]; then
         VMLINUZ=${VMLINUZ-"/lib/modules/${KVERSION}/vmlinuz"}
@@ -104,5 +116,5 @@ if [[ $* == *-initrd* ]]; then
     ARGS+=(-kernel "$VMLINUZ")
 fi
 
-echo "${0##*/}: $BIN ${ARGS[*]@Q} ${*@Q}"
+echo "${0##*/}: $BIN $(quote_args "${ARGS[@]}") $(quote_args "$@")"
 exec "$BIN" "${ARGS[@]}" "$@"