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

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

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


From: Aharon Robbins
Subject: Re: [Fwd: passing variables from awk-parent to bash-child]
Date: Fri, 06 Oct 2006 00:17:12 +0200

Greetings. Re this:

> Date: Thu, 05 Oct 2006 11:52:30 +0100
> From: "V. Mark Lehky" <address@hidden>
> Subject: [Fwd: passing variables from awk-parent to bash-child]
> To: address@hidden
>
> 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

As Andy pointed out in a separate mail, modifying ENVIRON doesn't
affect the environment seen by child processes.  If you change
the call to system() to something like:

        system ("MY_VAR=" ENVIRON["MY_VAR"] "; export MY_VAR; my_echo" )

it ought to work.

HTH,

Arnold




reply via email to

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