Requesting help with shell script

I have been viewing man pages and using google with little luck so far. I am writing a shell script using wbemcli.

I can execute the command and get the results I need just fine.

ex. wbemcli -nl ein 'http://<username>:<password>@<host>/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature'

from the command line, I will get back the instances available on the target pc like so.

<host>:5988/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\DTSZ_0"
<host>:5988/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\BATZ_0"
<host>:5988/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\CPUZ_0"
<host>:5988/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\LOCZ_0"
<host>:5988/<targetpc>/root/wmi:MSAcpi_ThermalZoneTemperature.InstanceName="ACPI\\ThermalZone\\VGAZ_0"

If an instance contains CPU, I want to grab the instance name, so I can execute the wbemcli command again to get specific property values.

The problem that I have is that the "http://..." string must be enclosed in single quotes. I have created variables in the script that will would replace the <username>, <password>, <host>, and <targetpc>, but from what I have read so far is that single quotes do no allow variable substitution.

I am not a complete noob to linux/unix, but I have never written something this complex previously. Any help would be greatly appreciated.

TIA,
Scott

You can start and stop the quotes whenever you want without chopping up the resulting string. (Unless any of the variables contain spaces, in which case it will still get chopped up.)

echo 'This does not substitute'${BUT_THIS_DOES}'Back in single quotes'

You can also try double quotes, which do allow substitution, and won't ever chop up the string:

echo "Hello world, VAR1=${VAR1}"

If there's things in your URL which do funny things in double quotes, you can escape them with \ so they're interpreted literally.

echo "This is a literal dollar sign --> \$ <-- see?"
1 Like

I belive you have issues with escaping if i got it correctly.

VAR="\'http://whateverdotsite\'"
printf $VAR"\n"

Thank you, Corona, by going and putting addition single qoutes around the variables, I was able to get it to work.