This is a very goofy workaround for you that doesn’t actually check what the device is. Only checks if /dev/sr0 exists and if yes, use that if no then use /dev/sr1. Better solution below this block. But leaving it because I kind of like it’s jankiness.
if [ -e /dev/sr0]; then
DEVICE="/dev/sr0"
else
DEVICE="/dev/sr1"
fi
Not elegant and a little janky but works.
This will work better. We are taking the output of -checkdrive, searching for “Detected” and sending that to awk. We are telling awk to split that line into columns based on this character “:” and to print the second column. That should give you an output of " /dev/sr0" with a space in front.
DEVICE=$(cdrecord -checkdrive | grep Detected | awk -F ":" '{print $2}')
That should work. But if you absolutely must kill the whitespace for some reason we can add trim to the end like so
DEVICE=$(cdrecord -checkdrive | grep Detected | awk -F ":" '{print $2}' | tr -d ' ')
There might be a more elegant solution by using the output of “cdrecord -scanbus” instead. No clue though since I don’t have the hardware to verify from here. Hope that helps!
My brain does not like. It’s stunlocked asking “why is this bold?” over and over again even though I already answered.