Validation sections are both a normal part of a document and a way to test if a prerequisite is run. This issue is about their use as a normal part of a document. In this mode the validation section should be run. Consider the example below which should output and/or test the value of UNIQUE_FILENAME when run in any mode.
ASIDE: I've written this example as both documentation and test script... where should it live?
How to use Environment Variables to Configure SimDem Scripts
It can be convenient to have a SimDem script that creates a number of environment variables for use in other scripts. This script can then be used as a prerequisite to ensure that you have a consistent environment on each execution. To set an environment variable use a command like the following:
You can use bash commands to create unique strings too:
UNIQUE_FILENAME=my_filename_$(date +%Y-%m-%d-%H)
If you want to avoid overwriting values provided by the SimDem user, you can easily do so with a value check:
if [ -z "$ANOTHER_UNIQUE_FILENAME" ]; then $ANOTHER_UNIQUE_FILENAME = my_filename_$(date +%Y-%m-%d-%H); fi
Validation
A validation section is useful in two ways. It can be used to ensure we output the final results when executing in a tutorial/demo environment and it can be used to test whether a prerequisite file needs to be run. For example:
if [ -z "$UNIQUE_FILENAME" ]; echo "We need to provide or generate a unique filename"; else "UNIQUE_FILENAME=$UNIQUE_FILENAME"; fi
Results:
UNIQUE_FILENAME=my_filename_yyyy-mm-dd-hh