Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion windows scripting with gawk
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Luuk  
View profile  
 More options Sep 15 2012, 11:20 am
Newsgroups: comp.lang.awk
From: Luuk <l...@invalid.lan>
Date: Sat, 15 Sep 2012 17:19:20 +0200
Local: Sat, Sep 15 2012 11:19 am
Subject: Re: windows scripting with gawk
On 15-09-2012 16:56, Manuel Collado wrote:

> El 15/09/2012 0:53, pop escribi :
>> Ed Morton said the following on 9/14/2012 1:35 PM:
>>> Serious_Developer <ehabaziz2...@gmail.com> wrote:

>>>> I must recall that thread because I did not find other group who could
>>>> be asked. Sorry for that inconvenience but I have to ask this again
>>>> for the urgent need .
>>>> I am calling that batch file that I want to return to it a value from
>>>> gawk script but it is not effective ????
>>>> ENVIRON["codeinsidebat"]=codeawk
>>> <snip>

>>> Ignoring the Windows/batch stuff it sounds like you're trying to change
>>> the value of an environment variable by changing it's value in the
>>> ENVIRON[] array within awk. You simply can't do that. ENVIRON contains a
>>> COPY of the environment variables names and associated values when awk
>>> starts up, that's all.

>>> Look (in UNIX, no idea what the Windows equivalent is):

>>> $ x=7; awk 'BEGIN{ ENVIRON["x"]=8; print ENVIRON["x"] }'; echo "$x"
>>> 8
>>> 7

>>> If you want to change the value of a variable in your environment as a
>>> result of executing an awk script then you need to have awk return that
>>> value and populate your variable from it, e.g.

>>> $ x=7; x=$(awk 'BEGIN{ ENVIRON["x"]=8; print ENVIRON["x"] }'); echo "$x"
>>> 8

>>> or generate a script to set the value and execute that script, e.g. with
>>> UNIX eval:

>>> $ x=7; eval $(awk 'BEGIN{ ENVIRON["x"]=8; print "x="ENVIRON["x"] }');
>>> echo
>>> "$x"
>>> 8

>>> Regards,

>>>     Ed.

>>> Posted using www.webuse.net

>> There is no unix/linux equivalent method to set an environment
>> variable in
>> windows as explained above. The only way I have been able to do it
>> (within
>> [g]awk) is as follows:

>> set x=7
>> echo %x%
>> 7
>> gawk "BEGIN{ x=8;print \"@set x=\"x >\"setx.bat\" }"
>> call setx
>> echo %x%
>> 8

>> Note that "call" is used if in a batch file and further batch statements
>> are present since a batch file is immediately exited without the "call".

>> HTH
>> pop is Mark

> On Windows XP and later:

> awk "BEGIN {exit 8}"
> set x=%ERRORLEVEL%
> echo %x%
> 8

Why on 'Windows or later'?
The same works on *nix ;)

#!/bin/bash
awk 'BEGIN{ exit 123}'
x=$?
echo $x


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.