Can I use aliases when using the ! and SYSTEM commands from within MATLAB?

46 views (last 30 days)
I rely heavily on using the aliases defined in my shell configuration file. I would like to be able to access these from within MATLAB with the ! or the SYSTEM command.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 Mar 2020
Edited: MathWorks Support Team on 2 Mar 2020
When using the ! or SYSTEM command, MATLAB forks off a non-interactive, non-login shell. Hence, depending on the shell being used only specific configuration files will be sourced.
The TCSH shell is more easily configurable for this task. To ensure that your aliases are recognized
1. Create a ~/.cshrc file with the aliases.
2. Create an environment variable MATLAB_SHELL=/bin/tcsh. When using the UNIX or ! commands, MATLAB queries this environment variable to check if a particular shell choice has been made.
Configuring a BASH shell for this task is more complicated because the non-interactive Bash shell does not read the ~/.bashrc file. Instead it queries the BASH_ENV environment variable for a file that must be executed at shell creation. Additionally, Bash does not expand (read substitute) aliases in non-interactive shells and hence one has to explicitly specify that it does this, to get this to work with a Bash shell
1. Set the variables, BASH_ENV=~/someFile and MATLAB_SHELL=/bin/bash.
2. Create a file ~/someFile that sets the appropriate aliases and include the following additional line
shopt -s expand_aliases
Note that on a Mac, setting global environment variables like MATLAB_SHELL and BASH_ENV requires one to edit a PLIST-file. Instructions on how to do this are available here:

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

No tags entered yet.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!