title: Execute Bash Script from PHP
body: <p>I am calling a bash script from PHP, but I have experienced a strange issue that only specific parameter value passed to bash can be successfully executed:</p>
  
  <p>My PHP code is simple:</p>
  
  <pre><code>$result = shell_exec("/scripts/createUser.sh $uname");
  </code></pre>
  
  <p>Bash script code:</p>
  
  <pre><code>#!/bin/bash
  
  export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  
  usrname=$1
  echo -e "Username: $1"
  
  deploy="/wordpress.tar.gz"
  dest="/data/$usrname"
  
  mkdir -p $dest
  
  cd $dest
  
  tar zxvf $deploy -C $dest &gt;/dev/null 2&gt;&amp;1
  
  ls $dest
  </code></pre>
  
  <p>However this script can only successfully mkdir, extract the wordpress.tar.gz and list the folder <strong>when $uname == 'test'</strong>, otherwise nothing happen (even cannot mkdir).</p>
  
  <p>I chown the script to www user and grant execution permission, no help. And  already tried run these commands via console as root, they run fine:</p>
  
  <pre><code>/scripts/createUser.sh admin
  php deploy.php // in this script $uname == 'admin'
  </code></pre>
  
  <p>How could this happen? Thanks for your idea!</p>