Variables containing spaces in lpadmin

I apologize for the long post. I have a lot of info...

I am trying to write a script that will add a network printer (or several) to a system using information read in from a text file. My problem is the spaces in the PPD file name, I'm not sure how to put the file name in or how to read it back so the spaces are read properly.

So, If I type this command:

lpadmin -p MyOfficePrinter -E -v lpd://my.server.ca/Office -P /Library/Printers/PPDs/Contents/Resources/en.lproj/HP\ LaserJet\ 4000\ Series.gz

It works fine. But of course I might want to name the printer something else, or use a different queue, or change the printer type.
My first attempt at using variables was:

PrintName="MyOfficePrinter"
PrinterQ="lpd://my.server.ca/Office"
PPDfile="/Library/Printers/PPDs/Contents/Resources/en.lproj/HP\ LaserJet\ 4000\ Series.gz"
lpadmin -p $PrinterName -E -v $PrinterQ -P $PPDfile

This would install the printer as a local printer and give an error:
lpadmin: add-printer (set model) faild: client-error-not-found

After running 'set -x' I was able to see that bash was expanding the command to:
+ lpadmin -p MyOfficePrinter -E -v lpd://my.server.ca/Office -P 'Library/Printers/PPDs/Contents/Resources/en.lproj/HP\' 'LaserJet\' '4000\' Series.gz

After this I tried a whole bunch of test variables and found (of course) that having backslash's in the variable was messing me up.

I tried a few different ways of putting this command together and the closest I got was:

PrintName="MyOfficePrinter"
PrinterQ="lpd://my.server.ca/Office"
PPDfile="/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 4000 Series.gz"
lpadmin -p $PrinterName -E -v $PrinterQ -P "$PPDfile"

Which expands to:

lpadmin -p MyOfficePrinter -E -v lpd://my.server.ca/Office -P '/Library/Printers/PPDs/Contents/Resources/en.lproj/HP\ LaserJet\ 4000\ Series.gz'

Which runs, does not generate an error, and the printer shows up in my printer list in System Preferences. But it does not print and does not have anything listed in it's installable options. So it partially installed the printer.

Other than going through my en.lproj folder and removing the spaces from all the file names, I can't think of anything else to do to make this work.

Can anyone out there help????

I would rename the PPD files to have "_" where they currently have space but if that is not possible then I would use:

lpadmin -p "${PrinterName}" -E -v "${PrinterQ}" -P "${PPDfile}"

to ensure any spaces in variables are handled correctly.

Thank you Tony,

That was exactly what I needed :b:!

I thought I had tried braces before, but going through my saved text doc from yesterday I see that I did not. I guess I didn't try everything after all :o

Thanks again for the help.