bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fwd: passing variables from awk-parent to bash-child]


From: V. Mark Lehky
Subject: [Fwd: passing variables from awk-parent to bash-child]
Date: Thu, 05 Oct 2006 11:52:30 +0100
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

Hello,

I suspect I might have found an "issue", unfortunately I do not know if it is in the program or documentation. :) Below is what I have posted to Usenet. I also tried to modify the below program to "print MY_VAR=different_value2; my_echo" into a pipe "/bin/sh", as is suggested in the manual section which describes the command 'system'. Nobody replied to this on Usenet, so I am turning to you in hopes of getting somewhere.

Thank You, VML.


-------- Original Message --------
Subject: passing variables from awk-parent to bash-child
Date: Thu, 28 Sep 2006 10:16:20 +0100
From: SiKing <address@hidden>
Organisation: A alphabetically be in organised sentence should words.
Newsgroups: comp.lang.awk,comp.unix.shell

Hello,

I am using gnu-awk 3.1.5 and bash 3.1.14 for the following.

I am trying to modify a (bash) environment variable (MY_VAR below) from an awk
script, and have that value propagate to a bash script child. I have managed to
distill my example down to the following:

main script:
#!/usr/bin/bash
export MY_VAR=value1
echo MY_VAR initial value is $MY_VAR
awk 'BEGIN {
        print "MY_VAR value is still " ENVIRON["MY_VAR"]
        ENVIRON["MY_VAR"] = "different_value2"
        print "MY_VAR different value is " ENVIRON["MY_VAR"]
        system( "my_echo" )
}' $0

my_echo script:
#!/usr/bin/bash
echo MY_VAR final value is $MY_VAR

The output is:
MY_VAR initial value is value1
MY_VAR value is still value1
MY_VAR different value is different_value2
MY_VAR final value is value1

What I was expecting was:
MY_VAR initial value is value1
MY_VAR value is still value1
MY_VAR different value is different_value2
MY_VAR final value is different_value2

Where have I gone wrong?
My current solution is to pass the value through a file. But I don't really like
that solution. Is there a better way of passing information in this direction?

TIA, SK.

--
"One of these days, milkshake, BOOM!"
  -- Evil Midnight Bomber What Bombs at Midnight
-----
Candy for spammers:
http://members.shaw.ca/grubb/spamthis.html

--
if my calculations are correct,
SLINKY + ESCALATOR = EVERLASTING FUN
<http://ca.blog.360.yahoo.com/egeer987>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]