LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-04-2009, 12:31 PM   #1
stuaz
Member
 
Registered: Dec 2008
Posts: 59

Rep: Reputation: 15
Programing Assistance - Splitting a string


Hello,

This question may be simple for some, but I require some assistance:

I have a script which will be sent something like this:
Code:
-oFtest -oEexample@example.com
So in my script I have a variable containing:
Code:
-oFtest -oEexample@example.com
Within my script I need to seperate the different -o's (options).

So eventually I would end up with multiple variables:
Code:
FORMAT='test'
EMAIL='example@example.com'
So I know the different options I will be sent, so I need to search the intial variable for the options I know will be there, if they are then I need to extract them out and place them in the correct varaible. Any options I shouldn't be expecting I will need to ether ignore or place in there own 'TEMP' variable.

Make sense??

Any help would greatly be apprieciated.
 
Old 07-04-2009, 04:41 PM   #2
rjwilmsi
Member
 
Registered: Mar 2005
Location: UK
Distribution: opensuse 12.2 x86_64
Posts: 563

Rep: Reputation: 38
You'd better tell us what language your script is going to be in.
 
Old 07-04-2009, 05:52 PM   #3
stuaz
Member
 
Registered: Dec 2008
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rjwilmsi View Post
You'd better tell us what language your script is going to be in.
Bash on a Linux system - Redhat or CentOS

Thanks,
 
Old 07-04-2009, 05:59 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Look at the `getopts' bash builtin command. The Advanced Bash Scripting guide (www.tldp.org) website will have examples.
Also look in the info bash manual.
 
Old 07-05-2009, 12:10 PM   #5
stuaz
Member
 
Registered: Dec 2008
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
Look at the `getopts' bash builtin command. The Advanced Bash Scripting guide (www.tldp.org) website will have examples.
Also look in the info bash manual.
OK I have had a look at the getopts command and functionality.

While I can get it to work in a simple script, if I try and use it in my printer driver script it fails, with messages such as:

Code:
lp: Warning - form option ignored
 
Old 07-06-2009, 04:57 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The -o option to pr sends printer dependent options to the printer. It sounds like the problem may be with one of options you sent to the printer, rather than a problem with your script. Check which options your printer or printer driver accepts. Check that the correct printer is being used.

You can precede the pr command with eval, which will fill the command line argument array. Examine what the arguments & environment variables are. Are they what you expect.
 
Old 07-13-2009, 09:10 AM   #7
stuaz
Member
 
Registered: Dec 2008
Posts: 59

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jschiwal View Post
The -o option to pr sends printer dependent options to the printer. It sounds like the problem may be with one of options you sent to the printer, rather than a problem with your script. Check which options your printer or printer driver accepts. Check that the correct printer is being used.

You can precede the pr command with eval, which will fill the command line argument array. Examine what the arguments & environment variables are. Are they what you expect.
My printer driver is bespoke, completelty created from scratch by myself. I figured I will keep it basic for now and just have one option sent to the driver. Which worked fine on my development machine.

When I moved my script over to the clients machine, it sends -oinv which is fine, however it also sends:

Code:
job-uuid=urn:uuid:354a84bd-a685-3a81-7d96-19b7ef288464
Which when on my development box it doesn't send. How can I stop it sending this??
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need assistance with shell script - replace a string with a start tag and end tag SupermanInNY Programming 18 01-02-2010 05:44 PM
MySQL splitting a string with a delimiter and taking the 1st value and update Lantzvillian Programming 7 01-31-2008 11:57 PM
Shell Script: Delete lines til string found or until particular string. bhargav_crd Linux - General 3 12-20-2007 11:14 PM
Programing expert assistance BobNutfield Fedora 1 01-18-2006 10:25 AM
Bash Script String Splitting MurrayL Linux - Newbie 1 09-21-2004 03:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration