Run multiple MPlus models on Linux
Are you using MPlus, the statistical package, on Linux and have become annoyed with the limitations of its command line client? In particular, have you ever wondered how to run multiple models with one command? If that is the case, you might want to consider putting the following into a shell script called, for example, mplus_run.sh
:
#!/bin/bash
for file in "$@"
do
/opt/mplus/8/mplus $file
kate ${file%.inp}.out &
done
This script will run MPlus for each input file you specify on the command line, and you can use shell expansions like *.inp
to run it on many files without having to specify them separately. By default, the script will open each output file generated by MPlus in a text editor in the background. I am using kate
, KDE’s text editor, to view the generated output files, but you can use any other graphical text editor. Just replace the name of kate
with your editor command in the above script. Note that the editor needs to be able to run in the background, so you can’t directly use a non-GUI editor such as vim, nano or emacs - you could open a new console window in your graphical user environment with the editor, however. If you do not want to automatically open the output files from MPlus, you can also just remove the line for running kate
.
You need to run chmod 755 mplus_run.sh
to make the script executable. You can either put it into your path and run it as mplus_run.sh
, or you can put it anywhere and create an alias, so that you can run it simply as mplus
. Edit your ~/.bashrc
or ~/.alias
file (depending on your Linux distribution) and add:
alias mplus='/path/to/where/you/put/mplus_run.sh'
That’s it. Now you can navigate to a folder full of MPlus models in various .inp
input files and can simply call:
mplus_run.sh *.inp
The shell script will run MPlus for each model and open the generated output file in the text editor you specified.
Comments
You can comment on this post on Mastodon.
If you want to comment with your Mastodon account at another instance, you can use the remote interaction buttons on mstdn.io or copy this URL into the search bar at your Mastodon instance to load the relevant toot: