AWK-Script to set a shell variable (Win32) ? 
Author Message
 AWK-Script to set a shell variable (Win32) ?

Hi,

Is there a simple solution to the following, theoretically simple
task: from within a Win32 shell [1] a small batch script (.bat) calls
an GAWK script which should set an ENVirnoment variable (or two or
more) as result. These variables then can be used by the original
batch script.

Well, the AWK script can issue a system("set myvar=123") command, but
the variables are then valid only for the shell instance which the
system command produces, not for the original shell instance (which
calles the AWK script).

Is there a simple solution, maybe?
If not, I've to fallback to file based "communication", which I would
like to avoid.
In Unix, I think one could do something like: myvar=`gawk -f
script.awk`
This would be my solution, however the thing has to run within
Win32... :-|

Thanks and greetings.
Oh well, please don't tell me this was off-topic. ;-)

-ric

[1] Aka Dosbox, command.com, or whatever the unhandy thing is being
called.



Mon, 26 Sep 2005 19:54:12 GMT  
 AWK-Script to set a shell variable (Win32) ?

...

Quote:
>In Unix, I think one could do something like: myvar=`gawk -f
>script.awk`
>This would be my solution, however the thing has to run within
>Win32... :-|

>Thanks and greetings.
>Oh well, please don't tell me this was off-topic. ;-)

>-ric

>[1] Aka Dosbox, command.com, or whatever the unhandy thing is being
>called.

Well, it is off-topic, because it has nothing to do with AWK and everything
to do with the whiles and wherefores of Windows and Windows command
interpreters.  If you hi thee over to alt.msdos.batch and/or
alt.msdos.batch.nt, they'll be more than happy to serve you.

Whatever you do, it is going to be very shell-specifc.  One solution, of
course, is to run a Unix-like shell (e.g., Cygwin bash) on Windows.
Barring that, what works in DOS-based versions of Windows (i.e.,
COMMAND.COM), might not work in NT-based versions (either CMD.EXE or the
fake COMMAND.COM).

For what it is worth, I think you can still modify the environment directly
(programmatically) in Win9x, but not in NT.



Mon, 26 Sep 2005 20:31:31 GMT  
 AWK-Script to set a shell variable (Win32) ?

Quote:

> Hi,

> Is there a simple solution to the following, theoretically simple
> task: from within a Win32 shell [1] a small batch script (.bat) calls
> an GAWK script which should set an ENVirnoment variable (or two or
> more) as result. These variables then can be used by the original
> batch script.


rem Have gawk set an environment var
rem that the rest of the batch script can use.
for /f %%A in (
  'gawk "BEGIN{print \"Output\"}"'
) do (
  set var=%%A
)
echo var=%var%
set var=

---- end awk_var.cmd ----

This won't work in Win9x as it uses features of cmd.exe that aren't
available with command.com.

Follow-ups set to alt.msdos.batch.nt.

Andrew Graham



Tue, 27 Sep 2005 01:09:54 GMT  
 AWK-Script to set a shell variable (Win32) ?
[..]

Quote:
> Whatever you do, it is going to be very shell-specifc.

Is there maybe a platform independant way how an AWK script could
return one several values to the calling script?
However I guess not, because it applies to any kind of program which
is being called, no matter whether it's "gawk -f script.awk" or
"myprogram parameter1" etc...
I think I'm asking for the impossible. Let's forget about it.

-ric



Tue, 27 Sep 2005 02:07:31 GMT  
 AWK-Script to set a shell variable (Win32) ?

Quote:


>[..]
>> Whatever you do, it is going to be very shell-specifc.

>Is there maybe a platform independant way how an AWK script could
>return one several values to the calling script?
>However I guess not, because it applies to any kind of program which
>is being called, no matter whether it's "gawk -f script.awk" or
>"myprogram parameter1" etc...
>I think I'm asking for the impossible. Let's forget about it.

>-ric

The core problem is that you are looking for a way to something fairly
advanced and sophisticated (not to mention, useful) on a "demo" command
interpreter running on a (or, more precisely, one of a series of) demo
computer OS(es).

Myself, when I do this, I usually end up doing:

        gawk ... > foo.bat
        call foo
        del foo.bat

It works well enough.



Tue, 27 Sep 2005 02:25:59 GMT  
 AWK-Script to set a shell variable (Win32) ?

Quote:




>>[..]
>>> Whatever you do, it is going to be very shell-specifc.

>>Is there maybe a platform independant way how an AWK script could
>>return one several values to the calling script?
>>However I guess not, because it applies to any kind of program which
>>is being called, no matter whether it's "gawk -f script.awk" or
>>"myprogram parameter1" etc...
>>I think I'm asking for the impossible. Let's forget about it.

>>-ric

>The core problem is that you are looking for a way to something fairly
>advanced and sophisticated (not to mention, useful) on a "demo" command
>interpreter running on a (or, more precisely, one of a series of) demo
>computer OS(es).

>Myself, when I do this, I usually end up doing:

>    gawk ... > foo.bat
>    call foo
>    del foo.bat

>It works well enough.

Unless the OS is known to be one of the NT versions, that is the
*only* way short of something extremely ugly that probably isn't
portable.

In the NT series of OSs there is something more or less like the Unix
approach:

  for /f "tokens=*" %%a in  ( 'gawk -f script files' ) do set foo=%%a

Come to think of it, that is pretty ugly and non-portable itself.




Tue, 27 Sep 2005 08:53:30 GMT  
 AWK-Script to set a shell variable (Win32) ?
[..]

Quote:
> The core problem is that you are looking for a way to something fairly
> advanced and sophisticated (not to mention, useful) on a "demo" command
> interpreter running on a (or, more precisely, one of a series of) demo
> computer OS(es).

Well, that's true, unfortunately. A demo OS rules the world. :-|
Unfortunatley my script has to run within that demo OS at the moment,
so I, and most of us, do follow the not so nice Gr?Faz Billy Gates.
:-(

However I see that your mentioned file based communication is the one
which is mostly platform independent.

I'll write the script with this in mind, and mabye use Andrew's and
Ted's mentioned Win32 specific method as a kind of optimization on
Win32. :-)

Thanks to your help, also to Andrew and Ted.

-ric



Wed, 28 Sep 2005 20:55:26 GMT  
 AWK-Script to set a shell variable (Win32) ?

Quote:



>> The core problem is that you are looking for a way to something
>> fairly
>> advanced and sophisticated (not to mention, useful) on a "demo"
>> command
>> interpreter running on a (or, more precisely, one of a series of)
>> demo
>> computer OS(es).

> Well, that's true, unfortunately. A demo OS rules the world. :-|
> Unfortunatley my script has to run within that demo OS at the moment,
> so I, and most of us, do follow the not so nice Gr?Faz Billy Gates.
> :-(

> However I see that your mentioned file based communication is the one
> which is mostly platform independent.

> I'll write the script with this in mind, and mabye use Andrew's and
> Ted's mentioned Win32 specific method as a kind of optimization on
> Win32. :-)

> Thanks to your help, also to Andrew and Ted.

> -ric

Richard,

You could install Win95Cmd on your non-NT-based machine(s).
It is essentially the NT command processor for Win9x/ME and
can be downloaded from Microsoft.  Andrew's code should work
on it AFAICR.

--
Peter S Tillier
"Who needs perl when you can write dc, sokoban,
arkanoid and an unlambda interpreter in sed?"



Sat, 08 Oct 2005 12:51:31 GMT  
 AWK-Script to set a shell variable (Win32) ?

[..]

Quote:
> You could install Win95Cmd on your non-NT-based machine(s).
> It is essentially the NT command processor for Win9x/ME and
> can be downloaded from Microsoft.  Andrew's code should work
> on it AFAICR.

Thanks for the hint. Most machines in the network here are NT based,
but a few are still Win95/98. I'll try to avoid them, but in case
they'll be used for my AWK scripts I'm going to try Win95Cmd (it's
always good to have a basic shell on them).

-ric



Sun, 16 Oct 2005 17:01:35 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Set expect script variables via a korn shell script

2. setting shell variables with results from awk

3. Setting variables from awk (c shell)

4. Passing command line variables to AWK in shell script

5. help for newbie: way to get the value of an awk variable in a shell script

6. Shell variable within an awk script

7. shell variable in awk script

8. awk variables --> shell variables

9. How do I display the contents of a shell variable from an awk script via a awk variable

10. using awk in a shell script...

11. trying to call awk from within a shell script

12. A simple question regarding shell scripts and awk

 

 
Powered by phpBB® Forum Software