Help about parse the variable

I'm using bash the code is

        QEMU_CMD="qemu-system-x86_64 -smp 2 -m 512 $QEMU_PARAMETER -hda $GUEST_IMAGE  -kernel $GUEST_KERNEL -append \"root=/dev/hda rw console=ttyS0,115200 ip=$IP_PARAMETER \" -nographic"
        echo "..............................."
        echo "qemu command is :"
        echo "$QEMU_CMD"
        echo "..............................."
        $QEMU_CMD

The log is

qemu command is :
qemu-system-x86_64 -smp 2 -m 512 -net nic,macaddr=52:54:00:65:43:21 -net tap,script=/etc/qemu-ifup -hda /boot/guest_raw.img  -kernel /boot/bzImage -append "root=/dev/hda rw console=ttyS0,115200 ip=dhcp " -nographic
...............................
qemu-system-x86_64: -append "root=/dev/hda: drive with bus=0, unit=0 (index=0) exists


Obviously, it parse the QEMU_CMD wrongly, but if I copy above log's cmd below it works well

qemu-system-x86_64 -smp 2 -m 512 -net nic,macaddr=52:54:00:65:43:21 -net  tap,script=/etc/qemu-ifup -hda /boot/guest_raw.img  -kernel  /boot/bzImage -append "root=/dev/hda rw console=ttyS0,115200 ip=dhcp "  -nographic

any help?

If you want to execute the command, you need to use command substitution.

QEMU_CMD=$(qemu-system-x86_64 ...)

It doesn't work still say "qemu-system-x86_64: -append "root=/dev/hda: drive with bus=0, unit=0 (index=0) exists"

You are getting an error from the command itself - you are trying to set up an emulated device that is already set up. I think you are misusing the command itself, which I know very little about.

NO, becasue I derectly use below cmd which print by echo "$QEMU_CMD" it works

qemu-system-x86_64 -smp 2 -m 512 -net nic,macaddr=52:54:00:65:43:21 -net tap,script=/etc/qemu-ifup -hda /boot/guest_raw.img  -kernel /boot/bzImage -append "root=/dev/hda rw console=ttyS0,115200 ip=dhcp " -nographic

Can you please show the exact command you are running (the one using command substitution, that is)?

GUEST_IMAGE="/boot/guest_raw.img"
GUEST_KERNEL="/boot/bzImage"
IP_PARAMETER="dhcp"
QEMU_IFUP_SCRIPT="/etc/qemu-ifup"
QEMU_PARAMETER="-net nic,macaddr=$GUEST_MAC -net tap,script=$QEMU_IFUP_SCRIPT"

        QEMU_CMD="qemu-system-x86_64 -smp 2 -m 512 $QEMU_PARAMETER -hda $GUEST_IMAGE  -kernel $GUEST_KERNEL -append \"root=/dev/hda rw console=ttyS0,115200 ip=$IP_PARAMETER \" -nographic"
        echo "..............................."
        echo "qemu command is :"
        echo "$QEMU_CMD"
        echo "..............................."
        $QEMU_CMD

It's really strange for me

Oh dear, I completely didn't see that you were running it using "$QEMU_CMD", on the last line there.

Is there any reason why you just cant run it directly without the variable. Or run it using eval $QEMU_CMD.

because I want to echo $QEMU_CMD
Aha it works with your cmd

I don't know why it doesn't work if I use below cmd, it will get that error too

QEMU_CMD=$(qemu-system-x86_64 -smp 2 -m 512 $QEMU_PARAMETER -hda $GUEST_IMAGE  -kernel $GUEST_KERNEL -append \"root=/dev/hda rw console=ttyS0,115200 ip=$IP_PARAMETER \" -nographic) 

"

Yes, forget the command substitution option. I misread your initial code.