PDA

View Full Version : How do I determine if a blank CD is in the drive? -- Bash Scripting -- HAL



_UsUrPeR_
July 3rd, 2008, 07:36 PM
I think I have this kind of figured out. That is to say, I have figured out how to get a "true" statement out of HAL.

Here's the code:


CDEmpty()
{
EMPTYCD=${"hal-get-property --udi '/org/freedesktop/Hal/devices/volume_empty_cd_r' --key volume.disc.is_blank"}

while [ "$EMPTYCD" != "true" ]
do
echo -n "Please insert a blank CD into the tray and push enter..."
Pause #this is a unlisted Pause function. It waits for user input.
EMPTYCD=${"hal-get-property --udi '/org/freedesktop/Hal/devices/volume_empty_cd_r' --key volume.disc.is_blank"}
done
}

If I try to run that, I get an error on the first "EMPTYCD=${etc..." line saying that is a bad substitution.

If I remove the "${...} " from the EMPTYCD variable, it leaves it as a variable storing a string instead of being executed with a return.

Can someone give me a hint about this?

geirha
July 3rd, 2008, 07:47 PM
You want to use $( ) or ` ` if you want to save the output of a command into a variable.

EMPTYCD=$( hal-get-property --udi '/org/freedesktop/Hal/devices/volume_empty_cd_r' --key volume.disc.is_blank )

_UsUrPeR_
July 9th, 2008, 07:44 PM
That did it! works great now. Thank you.