#set, #setenv, #unset, #unsetenv

With #set, and its variant #setenv, you can set environment variables.  You can then reference these environment variables in subsequent preprocessor directives, such as #exec, #include, #verbatim, and #echo.  (Note that legal environment variable names begin with a letter, followed by any sequence of letters, digits, and/or _ (underscore).)

So, for example, if you use

#set foo = "bar"
or the variant
#setenv foo "bar"
you could access the value of the $foo environment variable in a subsequent preprocessor directive.

If you don't specify a value, as in

#set foo
the environment variable is implicitly set to 1.  So the previous #set directive is equivalent to
#set foo = "1"
and
#setenv foo "1"
#unset and #unsetenv undo the effects of the #set and #setenv directives.  So
#unset foo
or
#unsetenv foo
leaves the environment variable $foo undefined.

You may set (or unset) environment variables in this way to #include (or not) files (i.e., processes cat'ing the file(s)), or to access environment variable values using the #echo command, to pass parameters to processes embedded within preprocessor directives (e.g., #include [<proc>], or #exec [<proc], or to do some other clever thing.

For example, if you do this in one of your config files

#set foo
#include <files/this_files.cfg>
#unset foo
you could have in this_files.cfg
#include [test $foo && /bin/cat /pikt/lib/configs/files/that_files.cfg]
or perhaps #include the output of some process
#include [/usr/local/bin/bar.pl]
where bar.pl references the $foo environment variable, for example with
if ($ENV{foo}) {
        ...
}
Together with the piktc -|+ E (un)set environment variable option, #set, #setenv, #unset, #unsetenv and the other preprocessor directives make a very powerful combination.  For some examples, refer to Samples and Developer's Notes.

prev page 1st page next page
Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software | DevNotes | Licensing | Authors | Pikt-Users | Pikt-Workers | Links | SiteIndex | ContactUs
Page best viewed at 1024x768.   Page last updated 2006-09-10.   This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.   Copyright © 1998-2006 Robert Osterlund.  All rights reserved.
Home FAQ News Intro Samples Tutorial Reference Software
PIKT Logo
PIKT Page Title