Launching scripts from bash and directing outputs
<p>I have a question about syntax of bash regarding launching scripts from within bash script.</p>

<p>My questions are:   </p>

<ol>
<li><p>I've seen the following syntax:</p>

<pre><code>#!/bin/bash
python do_something.py &gt; /dev/null 2&gt;&amp;1 &amp;
</code></pre>

<p>Can you please explain what is directed to <code>/dev/null</code>, and what is the meaning of <code>2&gt;&amp;1</code> if before already mentioned <code>/dev/null</code>?</p></li>
<li><p>In addition if I have a line defined like:</p>

<pre><code>python do_something.py &gt; 2&gt;&amp;1 &amp;
</code></pre>

<p>how is that different?</p></li>
<li><p>If I have the same python file in many paths, how can I differentiate between each process after launching <code>ps -ef |grep python</code>.
When I'm doing so, I get a list of processes which are all called <code>do_something.py</code>, it would be nice if I could have the full execution path string of each pid; how can I do that?</p></li>
</ol>

<p><strong>NOTE:</strong> The python file launched is writing its own log files.</p>

<p>Ok, <strong>diclaimer</strong>: I don't have access to a bash right now, so I might be wrong.</p>

<ol>
<li><p>Let's break your command: <code>python do_something.py &gt; /dev/null 2&gt;&amp;1 &amp;</code></p>

<p><code>python do_something.py</code> will run your command<br/>
<code>&gt; /dev/null</code> will redirect stdout to /dev/null<br/>
<code>2&gt;&amp;1</code> will redirect stderr to stdout<br/>
<code>&amp;</code> will fork your process and run in background</p>

<p>So your command will ignore stdout/stderr and be run in background which 
is equivalent to the command <code>python do_something.py &gt;&amp; /dev/null &amp;</code> <a href="http://superuser.com/questions/335396/what-is-the-difference-between-and-in-bash"><strong>[1]</strong></a><a href="http://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean"><strong>[2]</strong></a></p></li>
<li><p><code>python do_something.py &gt; 2&gt;&amp;1 &amp;</code>:</p>

<p><code>&gt; 2</code> will redirect stdout to a file named 2<br/>
<code>&gt;&amp;1</code> will redirect stdout to stdout (yes stdout to stdout)<br/>
<code>&amp;</code> will fork your process and run in background</p>

<p>So this command is <em>almost</em> equivalent to <code>python do_something.py &gt;2 &amp;</code>, 
it will redirect the output to a file named 2 (eg: <code>echo 'yes' &gt; 2&gt;&amp;1</code>)</p>

<p><strong>Note</strong>: the behavior of <code>&gt;&amp;1</code> is probably unspecified.</p></li>
<li><p>Since you have run your command using <code>&amp;</code>, your command will be fork and
run in background, therefore I'm not aware of any way to do it in that 
case. You can still lookup the <code>/proc</code> directory <strong>[3]</strong> to see from 
which directory your command have been run thought.</p></li>
</ol>

<p><strong>[1]</strong>: <a href="http://superuser.com/questions/335396/what-is-the-difference-between-and-in-bash">What is the difference between &amp;> and >&amp; in bash?</a><br/>
<strong>[2]</strong>: <a href="http://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean">In the shell, what does â 2>&amp;1 â mean?</a><br/>
<strong>[3]</strong>: <code>ls -l /proc/$PROCCESSID/cwd</code></p>

python linux bash