A number of environment variables are available in a Ghub tool session. A few are discussed here. A full list can be viewed by running the env command from a terminal in the Workspace tool, the noVNC Desktop, or the Terminal.
Remember: tools are invoked by the current user's account and all permissions are set accordingly. Therefore, a tool can save files to a user's home directory, because the tool runs as that user.
This variable stores the session ID or session number of the currently running tool. It's the ID of the session you are currently using. You can assume it's unique.
Notice that your current SESSION number is visible in your browser URL when you are running a tool. Here's an example:
The USER variable stores the username of the user running the current tool.
The SESSIONDIR variable stores the current session directory of the current tool run. A separate directory is created for each new tool session. Since it is created in the current user's home directory, the tool can write to this directory.
This is the recommended location for writing temporary files generated by your tool. Be mindful of the user's quota limits when writing temporary results. It's wise to delete these once the run is complete.
Session directories take the form:
The RESULTSDIR variable stores the results directory for the current tool run. It is located in the user's home directory. This is a good place to place simulation results and output for the user to access later.
Be mindful of the user's quota limits when writing results.
Results directories take the form:
This variable stores the present working directory.
This variable stores the full path to the user's home directory. This can be useful if a tool provides an option to save the user's current work. Tool developers should create a directory for the tool to save files relative to HOME, to prevent cluttering the user's home directory. For example, "$HOME/data/toolname".
Note that unlike the RESULTSDIR and SESSIONDIR described above, "$HOME/data/toolname" will not be created for each tool run.
Home directories take the form:
Accessing environment variables on Ghub
For a full list of environment variables, type this in a Workspace terminal:
To view the value of an environment variable from the Workspace terminal (sh or bash shell, e.g.):
From Jupyter's Python kernel, for example, use the shell escape: