I am looking into running matlab script in Linux similar to bash/python scripts. I.e., a matlab script that can be run as an application.
2 Answers
You can get a similar effect without your custom mash script by adding the following header to the files you want to be executable:
#/usr/bin/bash
/path/to/matlab -r "$(sed -n -e '4,$p' < "$0")"
exit $?
If you want matlab to terminate after executing the script, as in your example, you could replace the second line with
sed -n -e '4,$p' < "$0" | /path/to/matlab
The idea here is to execute a bash command that simply clips off the header of the script, and passes the rest along to matlab.
1 Comment
Here is the implementation I came up with -
Create
/usr/bin/mashscript file containing the following lines -#!/bin/bash grep -ve '^(#!\|^\s*$)' ${@: -1} | ${@: 1:$#-1} exit $?Make mash script executable -
$ chmod +x /usr/bin/mashWrite matlab script file called
test.msh#!/usr/bin/mash /usr/local/MATLAB/R2012a/bin/matlab -nodisplay format long a = 2*pi % matlab commands ...Make
test.mshscript executable -$ chmod +x mashRun
test.msh$ ./test.msh ... >> >> a = 6.283185307179586
2 Comments
/usr/bin; /usr/local/bin is a better place. /usr/bin is distribution-managed folder (or should be).;).