You want to write re-usable code, but want to allow the person running
the code to customise behaviour without having to change the code
itself.

A common way of achieving this is through environment variables.
Unfortunately, understanding exactly when you have access to a
particular variable in a Linux context can be confusing.

Note

In general, for code that will run only on SherlockML, we
suggest abstracting behaviour like this into a file in the
workspace, rather than through environment variables (for instance,
read how to do this for database credentials).

If your code needs to run both in SherlockML and in other
environments, environment variables are a good choice.

You may want to set an environment variable for a server so that it is
available everywhere in that server. For this, create a terminal in
that server and open /etc/sherlockml_environment.d/{app}.sh,
replacing {app} with any name that makes sense to you. For instance
to open the file with the text editor nano, run:

nano/etc/sherlockml_environment.d/app.sh

The file name must end in .sh. In that file, write the
following:

exportMY_ENVIRONMENT_VARIABLE=my_value

Any file in /etc/sherlockml_environment.d that ends in .sh
gets sourced
(executed in the current shell, rather than in a sub-shell) when you
open a new terminal or when the Jupyter or API or app process
starts. You can therefore use this to give all programs in your server
access to the same set of environment variables.

Any shell or program that is already running will need to be
restarted. In particular, to have the environment variables available
in Jupyter or JupyterLab, you will need to restart Jupyter:

sudosvrestartjupyter

You will then need to restart the kernel by clicking on Kernel >
Restart in the Jupyter or JupyterLab menu.