title: Run several matlab instances in a nohup bash script
body: <p>I'm trying to do something like the following.
  Right now, I connect via ssh to a remote machine and run my analysis with nohup command as</p>
  
  <pre><code>nohup matlab -nodesktop -nodisplay &lt; mycode.m &gt; output.txt 2&gt;&amp;1 &amp;
  </code></pre>
  
  <p>Now I want to write a script that runs in background several nohup commands one after the other one.
  I managed to do</p>
  
  <pre><code>#!/bin/bash
  matlab -nodesktop -nodisplay -r "mycode;quit;" &gt; output.txt
  </code></pre>
  
  <p>But not only the code works with one CPU only, but also it goes in an infinite loop and never finishes the job.</p>
  
  <p>I can I solve that?
  It is important that I could close the terminal after launching the script.sh</p>
  
  <p>EDIT:
  Thanks to you I manage to do and let the following thing to work well</p>
  
  <pre><code>ssh user@ipaddress
  screen
  cd folder1/
  nohup matlab -nodesktop -nodisplay &lt; mycode.m &gt; output.txt 2&gt;&amp;1 &amp;
  exit
  screen
  cd folder2/
  nohup matlab -nodesktop -nodisplay &lt; mycode.m &gt; output.txt 2&gt;&amp;1 &amp;
  exit
  </code></pre>
  
  <p>Now is it possible to do a script of that? Because I noticed that any time I type <code>screen</code> I have to press Enter right after.</p>
  
  <p>EDIT2: @Peter
  I did what you suggested</p>
  
  <pre><code>#!/bin/bash
  cd folder1/
  matlab -nodesktop -nodisplay -r "mycode;quit;" &lt; /dev/null  &gt; output.txt
  cd folder2/
  matlab -nodesktop -nodisplay -r "mycode;quit;" &lt; /dev/null  &gt; output.txt
  </code></pre>
  
  <p>But only the first matlab runs, how is it possible?</p>