Re: Question - reading command line parms inside a script.

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 03/11/04


Date: 11 Mar 2004 19:26:32 GMT

On Thu, 11 Mar 2004 at 14:37 GMT, Ken Andrews wrote:
> "Chris F.A. Johnson" <c.fa.johnson@rogers.com> wrote in message
>> Before we can diagnose the OP's problem any further, we need to
>> know more about what he's doing, and what the problem is exactly.

    I should have added, "Show the code that is giving you problems."
 
> Given:
>
> 1) Program (executable) called REFORMAT.exe, which takes a file and a set
> of parms and builds a new file from it. Example:
>
> reformat source.txt target.txt 1-20 -f=" >" 40-43 -f="< 40-43" -p122eqabc \
> 73-87 -f=" " 21
>
> The above will take all records from source where position 122 = a, b, or c
> and copy characters 1-20, 40-43, 73-87, and 21 into the target file, while
> putting " >", "< 40-43 ", and a space in the positions between the
> selections. The output lines would look like:
>
> xxxxxxxxxxxxxxxxxxxx >xxxx< 40-43 xxxxxxxxxxxxxxx x
>
> 2) New version of REFORMAT (different company) coming online that uses a
> different set of command parms, particulars unimportant.
>
> 3) Several hundred scripts have REFORMAT commands built into them, with
> lines such as in (1).
>
> 4) I'm trying to build a script called REFORMAT which will intercept the
> commands. My script version of REFORMAT will invoke a program that will
> decide if the given set of commands can be restructured and if so will do so
> and build a script to execute the new program. If it cannot, then it must
> fire the old version of REFORMAT and pass it the exact command strings as
> they were written in the invoking script.
>
> Example:
>
> Script alpha has the command line in (1) built into it.
>
> Script alpha now invokes the script REFORMAT.
>
> Script REFORMAT invokes program CHECK with the above command parms.
>
> CHECK decides whether or not it can convert the parms. If it can, it builds
> a temporary script using the converted parms. If it cannot, it builds a
> temporary script using the exact passed parms.
>
> Script REFORMAT executes the temporary script.
>
> CHECK must build the temporary script which invokes the original
> REFORMAT.exe using the exact parms above. It must receive and pass on
>
> -f=" >"
>
> It cannot receive or pass on
>
> -f= >
>
> If it passes the first, REFORMAT.exe will see one parm. If it passes the
> second, REFORMAT.exe will see one parm -f= and a second parm >.
>
> Right now CHECK is seeing -f= >, which it's interpreting as 2 parms. This
> gets very bad if it passes "< 40-43 " as 2 parms, as it will put in
> replacement data rather than text.

    If the line containing the quotes is being read from a file, the
    shell will not strip the quotes.

    You must be doing something to strip them. What is it?

    Are you forgetting to quote the variables that you pass to CHECK?
    In which case it is not stripping the quotes, but reading the
    argument as multiple words instead of one.

    Show the code that is giving you problems (both the calling and
    receiving end).

> Possibly I'm approaching this problem the wrong way (interception script
> with rebuilder program). If there's another way of doing it, I'd be very
> happy to know.

-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages