O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ENVIRON and SUBSET

The environment variable is an associative array containing the values of environment variables for the current process. The index of the array stores the environment variable name, and the elements are the values of particular environment variables. It is also helpful when we want to access the shell environment variable in our AWK script.

For example, the array element ENVIRON["HOME"] will contain the value of the HOME environment variable, ENVIRON["PATH"] will contain the value of the PATH environment variable, and so on. In the following example, we print all the available environment variables and their values:

$ vi  environ.awkBEGIN    {    OFS="="    for( v in ENVIRON )    print v, ENVIRON[v];    }$ awk -f envion.awk

The output ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required