args=( -append "opt with spaces" ) cmd "${args[@]}" other_arg
On Thu, Jan 13, 2022, 11:33 ju nan <kfg...@outlook.com> wrote: > I hava run into some troubles when I use bash shell to execute qemu, here > is the log. > > > > 1. Run qemu with arguments directly in bash shell, I use strace to > track execve syscall, everything goes well > > junan@u0:~/Documents/coding/run-riscv-qemu-linux$ strace > qemu-system-riscv64 -nographic -machine virt -kernel > ../linux-5.11/arch/riscv/boot/Image -append "root=/dev/vda ro > console=ttyS0" -drive file=root.ext4,format=raw,id=hd0 -device > virtio-blk-device,drive=hd0 > execve("/usr/bin/qemu-system-riscv64", ["qemu-system-riscv64", > "-nographic", "-machine", "virt", "-kernel", > "../linux-5.11/arch/riscv/boot/Im"..., "-append", "root=/dev/vda ro > console=ttyS0", "-drive", "file=root.ext4,format=raw,id=hd0", "-device", > "virtio-blk-device,drive=hd0"], 0x7ffc39cda858 /* 58 vars */) = 0 > brk(NULL) = 0x55bb77e20000 > arch_prctl(0x3001 /* ARCH_??? */, 0x7ffd61474450) = -1 EINVAL (Invalid > argument) > access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or > directory) > openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 > > > 1. But when I use bash variables to do it again, something wired > happend, as you can see, the argument "root=/dev/vda ro console=ttyS0" is > splited into different parts, so qemu did not start successfully 😋 > > > junan@u0:~/Documents/coding/run-riscv-qemu-linux$ echo $QEMU > qemu-system-riscv64 > junan@u0:~/Documents/coding/run-riscv-qemu-linux$ echo $QOPTIONS > -nographic -machine virt -kernel ../linux-5.11/arch/riscv/boot/Image > -append "root=/dev/vda ro console=ttyS0" -drive > file=root.ext4,format=raw,id=hd0 -device virtio-blk-device,drive=hd0 > > junan@u0:~/Documents/coding/run-riscv-qemu-linux$ strace $QEMU $QOPTIONS > execve("/usr/bin/qemu-system-riscv64", ["qemu-system-riscv64", > "-nographic", "-machine", "virt", "-kernel", > "../linux-5.11/arch/riscv/boot/Im"..., "-append", "\"root=/dev/vda", "ro", > "console=ttyS0\"", "-drive", "file=root.ext4,format=raw,id=hd0", "-device", > "virtio-blk-device,drive=hd0"], 0x7ffe1e71a928 /* 58 vars */) = 0 > brk(NULL) = 0x5613dfdc4000 > > > Thank you all for making so many excellent softwares, and I wish this will > help to improve the bash shell 😊. >