The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
bash - add backslash in front of variables w/ spaces trey85stang Shell Programming and Scripting 3 11-05-2008 05:32 AM
Read variables contain spaces from text file ahmed.zaher Shell Programming and Scripting 1 10-20-2008 07:44 PM
Assigning 'KSH' variables containing muliple spaces stv_t Shell Programming and Scripting 2 07-22-2008 04:59 AM
removing spaces from variables? yongho UNIX for Dummies Questions & Answers 2 06-10-2005 05:03 PM
lpadmin help andrec UNIX for Dummies Questions & Answers 2 09-13-2001 02:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-07-2009
HalfNube HalfNube is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Unhappy 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????
  #2 (permalink)  
Old 05-07-2009
TonyFullerMalv's Avatar
TonyFullerMalv TonyFullerMalv is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 748
I would rename the PPD files to have "_" where they currently have space but if that is not possible then I would use:

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

to ensure any spaces in variables are handled correctly.
  #3 (permalink)  
Old 05-08-2009
HalfNube HalfNube is offline
Registered User
  
 

Join Date: May 2009
Posts: 2
Smile

Thank you Tony,

That was exactly what I needed !

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

Thanks again for the help.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:50 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0