Change Environment Variable for Shell Command - MATLAB & Simulink (original) (raw)

Main Content

This example shows how to substitute a user-specified value for an environment variable value set by MATLAB® when you call a function using the system command.

When you use the system command to call a function, the function inherits the MATLAB environment. To change environment variable values, use a shell wrapper. Use the environment variable MATLAB_SHELL to specify a shell containing your updated variable. This example uses a custom value for the environment variable LD_LIBRARY_PATH.

Create a wrapper file matlab_shell.sh in the folder_<PATHTOSHELLSCRIPT>_ with the following contents, where <MYLIBRARYPATH> is your custom value.

#!/bin/sh

LD_LIBRARY_PATH= export LD_LIBRARY_PATH

exec SHELL:−/bin/sh{SHELL:-/bin/sh} SHELL:/bin/sh*

If you have a user-defined value for SHELL, the expression${SHELL:-/bin/sh} uses your SHELL value. Otherwise, MATLAB uses the Bourne shell.

From the operating system prompt, call MATLAB setting MATLAB_SHELL to:

/matlab_shell.sh

Display your value of LD_LIBRARY_PATH from the MATLAB command prompt.

Now when you call a function using the system command, the function uses the LD_LIBRARY_PATH value specified by_<MYLIBRARYPATH>_.

See Also

system