title: retrieving pid in unix startup script
body: <p>in a simple startup script I wrote I have:  </p>
  
  <pre><code>PID=`su user_name -c "daemon_name &gt; /dev/null 2&gt;&amp;1 &amp; echo \$!"`  
  echo $PID  
  </code></pre>
  
  <p>The script is run as <code>root</code>. And the echo doesn't really echo anything :)</p>
  
  <p>If I input the exact same command in the shell, it works:  </p>
  
  <pre><code># su user_name -c "daemon_name &gt; /dev/null 2&gt;&amp;1 &amp; echo \$!"  
  11831  
  #  
  </code></pre>
  
  <p>Any ideas? Thanks.  </p>
  
  <p>EDIT: It was working fine before I tried to run the application as another user.<br>
  I was previously using this code:  </p>
  
  <pre><code>PID=`daemon_name &gt; /dev/null 2&gt;&amp;1 &amp; echo $!`  
  echo $PID  
  </code></pre>
  
  <p>and it worked fine as <code>root</code></p>