The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 01-05-2009
JerryHone JerryHone is offline
Registered User
  
 

Join Date: Nov 2006
Location: UK
Posts: 178
Quote:
Originally Posted by mirusko
is there a way how to export the variable from within the AWK command
The simple answer is no. The awk script is running as a subshell and there's no way to make a child process alter the environment of its parent.

Having said that, the awk process can create a file (say, /tmp/awk.env) with the content
Quote:
export X=<x>
where <x> is the new value. In your parent script, you then source the env file i.e.
Quote:
awk -v x=$X ...
. /tmp/awk.env
NOTE: By having the "export" in env file, it's not necessary to pass $X into the next awk call as it's now available in the parent's environment.

HTH

Jerry