3

I have read this thread on how to correctly add the paths:

How to correctly add a path to PATH?

I have already exported path

/usr/local/proc_mt/bin:usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin

Still I do not know how should I change my matlab shell script, in a way that would enable me to use the matlab.

1 Answers1

0

In the shell script, simply include the following:

PATH="$PATH:/usr/local/proc_mt/bin:usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin"

If there are executables with the same name as other executables in your $PATH, and you wish to give the Matlab executables preference over the others, put it before your current environment $PATH like so:

PATH="/usr/local/proc_mt/bin:usr/local/MATLAB/MATLAB_Production_Server/R2015a/bin:$PATH"

In some scenarios you may need to export this environment variable by doing

export PATH=[the solutions I listed above]

...which can never hurt (and in some cases may make obscure issues easier to troubleshoot)

The issue you are probably experiencing is that you are setting the $PATH in your shell, and the actual script is defaulting to the default environment $PATH. You can avoid this, as said before, by explicitly setting the $PATH from within the script itself.

rubynorails
  • 2,293
  • Are you thinking of matlab shell script?Should I change the ownership? -r-xr-xr-x 1 root root 58454 Dez 29 2014 matlab – MikiBelavista Nov 23 '15 at 16:22
  • Only if you are running it as root. Otherwise, chown to the user who will be running the script. If the name of your script is simply matlab and there is also an executable in your $PATH called matlab, then that is your problem. Change the name of the script to somethingelse.sh – rubynorails Nov 23 '15 at 19:19
  • but how did you find the location of the binaries files or MATLAB in the first place? – Charlie Parker Feb 01 '16 at 18:10
  • What is proc_mt suppose to be? this doesn't work for me, how did u find out what directory paths to put in there? – Charlie Parker Feb 01 '16 at 19:29
  • @CharlieParker - that's just part of this specific user's $PATH, which is a directory (probably unrelated to MATLAB) that includes executable files which can be referenced directly by name rather than their full path. My answer was not MATLAB-specific; it answered the question of how to correctly set a $PATH environment variable for a shell script. One must find one's own $PATH by executing echo $PATH. If you want a script that uses MATLAB executables, find where they exist, and include export PATH="/path/to/MATLAB/bin/directory:${PATH}" in your shell script. – rubynorails Feb 02 '16 at 05:06
  • Note: if you do it this way and there are executables in that directory that share a name with other executables found further along in your $PATH -- say /usr/bin for example -- if MATLAB has an executable called find, it will be referenced instead of the normal find command located in /usr/bin, which you would have to reference by full path in order to execute it in the script. If there are no executables with the same name, or you want the usual ones to take precedence, put the MATLAB bin directory at the end of your $PATH: export PATH="${PATH}:/path/to/MATLAB/bin/directory". – rubynorails Feb 02 '16 at 05:13