title: When using php exec() to run shell scripts, one script works (which simply does git status) and one doesn't (which does git checkout). How come?
body: <p>I am trying to setup a web-based portal through which we can checkout different branches of our Git repository through a simple click on a back-end panel.</p>
  
  <p>So currently, I have /var/www/devportal which contains <strong>index.php</strong>, <strong>status.sh</strong> and <strong>checkout.sh</strong></p>
  
  <p>In <strong>index.php</strong> I do the following:</p>
  
  <pre><code>$repo = $_GET['repo'];
  $command = 'sh status.sh ' . $repo;
  $output = exec($command);
  echo "&lt;pre&gt;$output&lt;/pre&gt;";
  </code></pre>
  
  <p>The contents of <strong>status.sh</strong> are:</p>
  
  <pre><code>#!/bin/bash -e
  if [ $# -ne 1 ]
  then
      echo "Usage: `basename $0` &lt;repo name&gt;"
      exit 1
  fi
  cd /var/www/$1
  git status
  </code></pre>
  
  <p>And this works just fine. The output echoed in PHP shows me the status of the current branch within /var/www/proj.</p>
  
  <p>Now when I try to do the same thing (passing 2 parms this time with the second one being the name of the branch to checkout) with <strong>checkout.sh</strong>, who'se contents are:</p>
  
  <pre><code>#!/bin/bash -e
  if [ $# -ne 2 ]
  then
      echo "Usage: `basename $0` &lt;repo name&gt; &lt;branch name&gt;"
      exit 1
  fi
  cd /var/www/$1
  git checkout $2
  </code></pre>
  
  <p>It doesn't work. Not only does it not work, I don't get diddly squat for an error message. There is no output. I know that the checkout.sh script works fine because when I echo the command that is being sent via PHP's exec command, copy that exact thing and run it via terminal logged in as root, it works just fine, does the checkout and returns the name of the newly activated branch.</p>
  
  <p>Any tips on this would be greatly appreciated. My box is pretty standard, Ubuntu 10.04 and running Apache2.</p>
  
  <p>Thanks!</p>