"Ed Morton" <morton@[EMAIL PROTECTED]
> wrote in message
news:48002C0E.9000908@[EMAIL PROTECTED]
> On 4/11/2008 10:12 PM, Rajan wrote:
>>
>> "Ed Morton" <morton@[EMAIL PROTECTED]
> wrote in message
>> news:480020FF.1020403@[EMAIL PROTECTED]
>>
>>>
>>>On 4/11/2008 9:16 PM, Rajan wrote:
>>>
>>>>I have an application which interacts with the user using a command
line
>>>>program. I get files which have some information that needs to be
parsed
>>>>and
>>>>then be sent as commands to my application. The output is then
processed
>>>>again using some gawk. Now the problem is my application's command has
>>>>some
>>>>patterns which look like shell variables, regular expressions and
shell
>>>>regular expressions. If I run this from gawk's system it p*****
through
>>>>the
>>>>shell and shell tries to expand them which makes the commands appear
>>>>weird
>>>>to my application.
>>>>
>>>>sample text from input file
>>>>
>>>>itemID,B9746
>>>>orderID,97733
>>>>itemID,A7632
>>>>itemID,B3328
>>>>
>>>>the commands look like
>>>>
>>>>my_command_parsing_prog list all itemID itemName qty -when $(itemID)
>>>>like
>>>>'B9746.*'
>>>>my_command_parsing_prog list top 10 orderID salesCenter
>>>>supplyCenter -when
>>>>$(orderID) match '^97733.*' -sort byMatch
>>>>
>>>>When I try to say system <one of above command> the *s and $s are
>>>>expanded
>>>>by shell. Is there a way to run the command without passing them
through
>>>>the
>>>>shell?
>>>>
>>>>Rajan
>>>>
>>>
>>>Maybe we can simplify the problem description. I think you want to do
>>>this:
>>>
>>>$ ls
>>>a b
>>>$ awk 'BEGIN{system("echo *")}'
>>>a b
>>>$ awk -v q=\' 'BEGIN{system("echo " q "*" q)}'
>>>*
>>>
>>>i.e. stop the wildcards in the string you pass to system() from being
>>>expanded
>>>by the shell. If so, just quote them as above.
>>>
>>>Ed.
>>>
>>
>>
>> Thanks, but as you see the commands have single quotes in them so
>> system("echo \" * \"") should work.
>
> How do you know it doesn't "work"? i.e. what makes you think it's the
> system()
> call that's causing the wildcard expansion and not some other part of
your
> program?
>
This does work. If the string has as string has something like $item shell
is trying to expand it. Since I am double quoting it. If I single quote
it,
the single quotes inside of the string are causing a problem.
>> This gives me the other problem variable
>> substitution. Is there a way we can pass a string with single quotes
and
>> things that look like shell variables / expressions to another program
>> without going through the shell?
>>
>> Rajan
>>
>
> I think you'll need to show a SMALL sample program (like the one I
posted)
> that
> demonstrates the problem along with sample input, expected output, and
the
> output you actually get.
>
> I also think you should post this to comp.unix.shell instead of here as
> it's
> more of an OS question than an awk one.
>
> Ed.
>
Let us make this more simple and generic. The question is can I run a
command with arguments containing $HOME , single quote and *s without a
lot
of hopping in and out of quotes. Something like the system in perl
(http://perldoc.perl.org/functions/system.html)
which when multiple
arguments are passed sends all the strings as is to the first element
without passing them through the shell? To be more generic, does system
command always pass the command through the shell or is there a way the
command can be invoked directly without shell looking at its arguments?
Any
information would help.
Rajan


|