These variables, such as $GITHUB_ENV, $ENV0_ENV, etc., simply point at a file that is sourced to populate an environment with the contained code, much like a .bashrc file.
These enviornment variables, while convenient, present a great amount of difficulty if they're not understood. Errors like ambiguous redirect
, or no such file or directory
, are common. In the worst case they get deleted, in which case they'll have to be re-created with the default content.
Beyond the simple foobars that users might have with this convenience utility, they also present an additional challenge in that they may persist data that is deisrable to delete. Clearing this data is another challenge. See below for more.
$ # Create the environment variable
$ COOL_ENV=~/.COOL_ENV
$ # Populate the file with a key/value (variable)
$ echo "foo=bar" >> $COOL_ENV
$ # Check the file contents
$ cat $COOL_ENV
foo=bar
$ # Source the file
$ source $COOL_ENV
$ Show that foo is now set
$ echo $foo
bar
This function is an example of one you might setup to make maintenance of variables easier. Note that this function itself can be placed in an _ENV file, with a bit of escaping.
function expunge_envar() {
[[ $# -ne 2 ]] && echo "ERROR: Must provide exatly two args: the variable to sanitize, and the ENV variable or file to remove it from."
local var=$1
local env_file=$2
# Unset the var
unset $var
sed -i "/${var}=/d" $env_file
}
expunge_envar foo $COOL_ENV