sgdisk behaviour

Hello.

1°) When I run this piece of code :

...
    echo "sgdisk -d $DEVICE_PARTNUMBER  $DISK_DEVICE"
    echo " "
    sgdisk -d "$DEVICE_PARTNUMBER  $DISK_DEVICE"
    RET_CODE=$?
    echo "\$?   : $RET_CODE"

....

I got this error :

sgdisk -d 1  /dev/sdd
 
Problem opening   /dev/sdd for reading! Error is 2.
The specified file does not exist!
$?   : 2


2°) When I use bash “eval” command


.....
     CMD="sgdisk -d $DEVICE_PARTNUMBER  $DISK_DEVICE"
    echo "CMD : $CMD"
    eval "$CMD"
    RET_CODE1=${PIPESTATUS@]}
    RET_CODE2=$?
    echo "PIPE STATUS : $RET_CODE1"
    echo "\$?          : $RET_CODE2"
....

I got no error :

CMD : sgdisk -d 1  /dev/sdd
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
PIPE STATUS : 0
$?                : 0


3°) When I run this command from a kde console I got no error :


sgdisk -d 1  /dev/sdd
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

Any help is welcome.

I’m not sure what you are trying to do there.

When you use:

sgdisk -d "$DEVICE_PARTNUMBER  $DISK_DEVICE"

you are doing something like:

sgdisk -d weird-device-name-that-contains-spaces

That’s because of your quoting.

You presumably needed either:

sgdisk -d $DEVICE_PARTNUMBER  $DISK_DEVICE

or

sgdisk -d "$DEVICE_PARTNUMBER"  "$DISK_DEVICE"

so that there are two arguments following the “-d”.

When you use “eval”, the “eval” removes the quotes and parses the string before running the command. So the problem with quotes is no longer there.

I’m not sure what you thought you were asking about. I’m taking your post as a question about shell quoting.

Because I had not seen that I have misquoted the statement (surely tired) I was wondering why it was behaving differently.
Of course the correct syntax is

sgdisk -d "$DEVICE_PARTNUMBER"  "$DISK_DEVICE"

Thank you to see it.

And happy new year !