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

From: Nick Landsberg (hukolau_at_NOSPAM.att.net)
Date: 03/11/04


Date: Thu, 11 Mar 2004 21:40:05 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.
>
>
> 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

Ah ... OK ... now I think I understand.

Note that the quoting above is there to prevent the shell
from interpreting the special characters < and > and also
to prevent it from taking the space as an argument separator.
The comman line you noted above is functionally equivalent to:

reformat "source.txt" "target.txt" "1-20" "-f= >" "40-43" "-f=< 40-43"
"-p122eqabc" "73-87" "-f= " "21"

(although no one would type it in this way!)

The following script:

for arg in "$@"
do
         echo \"$arg\"
done

has the following output when run against your original command line:

"source.txt"
"target.txt"
"1-20"
"-f= >"
"40-43"
"-f=< 40-43"
"-p122eqabc"
"73-87"
"-f= "
"21"

Is this what you wanted?

HTH

>
> 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.
>
>
> 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.
>
>

-- 
Ñ
"It is impossible to make anything foolproof because fools are so 
ingenious" - A. Bloch


Relevant Pages