Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameters 2

Status
Not open for further replies.

mjm22

Programmer
Nov 11, 2003
10
GB

Hi

I have a wrapper script that I call, passing a number of parameters ...

wMFM.sh -p 83 -w '20041001 18550900' -r 83 '-a -nls _.UTF8'

parameter names -p, -w and -r are always present. -a is a list of additional parameters that may be used. If I echo the count of parameters I get 7 since the date is passed as one field as is the list of additional parameters.

The script is ksh and after doing a bit of work the idea is that I pass on the parameters to the program that I wish to run (previously the calling routine would have done this directly).

So I store the above values to a variable - $PLIST

Then call my program...

MFM $PLIST

However MFM complains because the now the parameter list effectively looks like this (quotes added by me to show elements)...

'-p' '83' '-w' '20041001' '18550900' '-r' '83' '-a' '-nls' '_.UTF8'

Since MFM is expecting the date in the format YYYYMMDD HHMISSTT it fails.

I have tried to format the $PLIST variable so it looks like when I echo it....

-p 83 -w '20041001 18550900' -r 83 '-a -nls _.UTF8'

but I get the same problem. Howevre if I make a call to MFM using the hard-coded value of above then it works.. i.e.

MFM -p 83 -w '20041001 18550900' -r 83 '-a -nls _.UTF8'

I have even tried to store each parameter to an array and then pass these to the MFM like...

MFM ${A[1]} ${A[2]} ${A[3]} echo `\'${A[4]} ${A[5]}\'` ....

but I still get the error. I guess that this is being cause by some kind of substitution of the '' at runtime but I cannot figure out how to fix this.

Any ideas would be appreciated.

Thanks in advance.
 
Hi:

Build PLIST so you have escaped double quotes around the arguments that will have white space. Then build another string with the script to execute and append the PLIST arguments. Finally, eval that string which forces the shell to make another pass thru the arguments, hopefully, giving you what you want:

PLIST="-p 83 -w \"20041001 18550900\" -r 83 \"-a -nls _.UTF8\""
eval "wMFM.sh $PLIST"

Regards,

Ed
 
I don't think you need to use escaped char:
PLIST="-p 83 -w '20041001 18550900' -r 83 '-a -nls _.UTF8'"
eval "MFM $PLIST"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top