Environment Variables in Scilab
Environment variables are a universal mechanism for conveying configuration information to Unix programs. Let’s look at how to set, get, and list environment variables.
Running the program shows that we pick up the value for FOO
that we set in the program, but that BAR
is empty.
The list of keys in the environment will depend on your particular machine.
If we set BAR
in the environment first, the running program picks that value up.
In Scilab, we use setenv
to set environment variables and getenv
to retrieve them. The lines(getenv())
function is used to get all environment variables as a matrix of strings. We then use a for loop and strsplit
to separate and display the keys.
Note that in Scilab, we typically save our scripts with a .sce
extension and run them using the scilab -nw -f
command in the terminal, where -nw
stands for “no window” (console mode) and -f
is followed by the script filename.