title: "How to run a single command as a background process using su -c
body: <p>Running by hand,</p>
  
  <pre><code>adb shell
  su
  chmod 666 /dev/graphics/fb0
  export CLASSPATH=/data/local/device.jar
  export LD_LIBRARY_PATH=/data/local
  exec app_process /system/bin com.device.client.Main /data/local/device.conf &amp;
  </code></pre>
  
  <p>Performs as expected.</p>
  
  <p>However, trying to run this from a bash script using the following command does not work as expected.</p>
  
  <pre><code>adb shell "su -c '
  chmod 666 /dev/graphics/fb0
  &amp;&amp; export CLASSPATH=/data/local/device.jar
  &amp;&amp; export LD_LIBRARY_PATH=/data/local
  &amp;&amp; exec app_process /system/bin com.device.client.Main /data/local/device.conf &amp;'"
  </code></pre>
  
  <p>It works without &amp;, but with &amp; it just won't start the binary. <strong>exec app_process has to be a background process.</strong></p>
  
  <p>It's possible that the shell executes the binary but then just dies, because it does not wait on anything else, but I don't know how to fix it. Making su a background process should do it, '&amp;" but it didn't work.</p>
  
  <p>When running without &amp;, we get:</p>
  
  <pre><code>D/su ( 1728): 0 /system/bin/sh executing 0 
  D/su ( 1728): chmod 666 /dev/graphics/fb0
  D/su ( 1728): &amp;&amp; export CLASSPATH=/data/local/device.jar
  D/su ( 1728): &amp;&amp; export LD_LIBRARY_PATH=/data/local
  D/su ( 1728): &amp;&amp; exec app_process /system/bin com.device.client.Main /data/local/device.conf using shell /system/bin/sh : sh
  </code></pre>
  
  <p>When adding &amp;, we get:</p>
  
  <pre><code>D/su ( 1746): 0 /system/bin/sh executing 0 
  D/su ( 1746): chmod 666 /dev/graphics/fb0
  D/su ( 1746): &amp;&amp; export CLASSPATH=/data/local/device.jar
  D/su ( 1746): &amp;&amp; export LD_LIBRARY_PATH=/data/local
  D/su ( 1746): &amp;&amp; exec app_process /system/bin com.device.client.Main /data/local/device.conf &amp; using shell /system/bin/sh : sh
  </code></pre>
  
  <p>but nothing gets loaded!</p>
  
  <p>How can I run my set of commands, ensuring that app_process will run in the background?</p>