bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A bug when using bash shell variable


From: Alex fxmbsw7 Ratchev
Subject: Re: A bug when using bash shell variable
Date: Thu, 13 Jan 2022 11:45:03 +0100

in other words
shell separates between spaces and quotes
u need quoting right, otherwise its flat args or one arg if quoted not right

arr=( -arg{1,2,3} )
cmd "${arr[@]}"

tells to pass every arr member with quotes

On Thu, Jan 13, 2022, 11:42 Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com> wrote:

> args=( -append "opt with spaces" )
> cmd "${args[@]}" other_arg
>
> On Thu, Jan 13, 2022, 11:33 ju nan <kfggww@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 😊.
>>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]