Using bash shell inside Matlab
Date: 2022-09-15 15:40:31
I'm trying to put a large set of bash commands into a matlab script and manage my variables (like file paths, parameters etc) from there. It is also needed because this workflow requires manual intervention at certain steps and I would like to use the step debugger for this.
The problem is, I don't understand how matlab interfaces with bash shell. I can't do system('source .bash_profile')
to define my bash variables. Similarly I can't define them by hand and read them either, e.g. system('export var=somepath')
and then system('echo $var')
returns nothing.
What is the correct way of defining variables in bash inside matlab's command window? How can I construct a workflow of commands which will use the variables I defined as well as those in my .bash_profile?
answer:
If all you need to do is set environment variables, do this in MATLAB:
>> setenv('var','somepath')
>> system('echo $var')