Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One easy solution is to use:</p> <pre><code>ssh localhost "(cd /tmp &amp;&amp; nohup sleep 10) &gt;/dev/null 2&gt;&amp;1 &amp;" </code></pre> <p>(this also works if you use braces, see second example below).</p> <p>I did not experiment further but I am reasonably convinced it has to do with open file descriptors hanging around. Perhaps zsh and dash bind the <code>&amp;&amp;</code> so that this means what has to be spelled as:</p> <pre><code>{ cd /tmp &amp;&amp; nohup sleep 10; } &gt;/dev/null 2&gt;&amp;1 </code></pre> <p>in bash.<hr>Nope, quick experiment in dash shows that <code>echo foo &amp;&amp; echo bar &gt;file</code> only redirects the latter. Still, it has to have something to do with lingering open fd's causing ssh to wait for more output; I've run into this a lot in the past. <hr> One more trick, not needed if you use the parentheses or braces for this particular case but might be useful in a more general context, where the set of commands to do with <code>&amp;&amp;</code> are more complex. Since bash seems to be hanging on to the file descriptor inappropriately with <code>&amp;&amp;</code> but not with <code>;</code>, you can turn <code>a &amp;&amp; b &amp;&amp; c</code> into <code>a || exit 1; b || exit 1; c</code>. This works with the test case:</p> <pre><code>ssh localhost "true || exit 1; echo going on; nohup sleep 10 &gt;/dev/null 2&gt;&amp;1 &amp;" </code></pre> <p>Replace <code>true</code> with <code>false</code> and the echo of "going on" is omitted.</p> <p>(You can also <code>set -e</code>, although sometimes that is a bigger hammer than desired.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload