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 ...

Get Learning AWK Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.