title: Run python script with dot slash ./
body: <p>I installed two python 2.7.3 into my home directory</p>
  
  <pre><code>   one is for Linux:           /home/luban/Linux/Python/2.7.3
     another is for Solaris:   /home/luban/SunOS/Python/2.7.3
  </code></pre>
  
  <p>then I create a wrapper named "python" in /home/luban/bin to call the different python when I am working on different systems.</p>
  
  <p>[luban@lunbanworks 1] ~ > cat /home/luban/bin/python</p>
  
  <pre><code>#!/bin/sh
  
  CMD=`basename $0`
  
  OS=`uname -s`
  
  
  CMD_PATH="/home/luban/$OS/Python/2.7.3/bin"
  
  
  if [ -x "${CMD_PATH}/${CMD}" ];then
  
      export PATH="${CMD_PATH}:${PATH}"
  
      exec ${CMD_PATH}/${CMD} ${1+"$@"}
  
  else
  
      echo "${CMD} is not available for ${OS}" 1&gt;&amp;2
  
  exit 1
  
  fi
  </code></pre>
  
  <p>&nbsp;</p>
  
  <pre><code>[luban@lunbanworks 2] `ls -l /home/luban/bin/python`
  
  -rwxrwxr-x  1 luban lunban  221 Apr  5 19:11 python*
  </code></pre>
  
  <p>I use below script to  test the wrapper <code>/home/luban/bin/python</code></p>
  
  <pre><code>[luban@lunbanworks 3] ~ &gt; cat myscript.py
  
      #!/home/luban/bin/python
  
      myname="lunban"
  
      print "myname is %s" % myname
  
  [luban@lunbanworks 4] chmod +x myscript.py
  </code></pre>
  
  <p>I want to use <code>./ run myscript.py</code></p>
  
  <pre><code>[luban@lunbanworks 5] ~ &gt;./myscript.py
  
      myname=luban: Command not found.
      lpr: Unable to access "myname" - No such file or directory
  </code></pre>
  
  <p>use <code>/home/luban/bin/python myscript.py</code> can work:</p>
  
  <pre><code>[luban@lunbanworks 5] ~ &gt; `/home/luban/bin/python myscript.py`
  
      myname is luban
  </code></pre>
  
  <p>After I change the shebang line to <code>#!/home/luban/Linux/Python/2.7.3/bin/python</code>, use <code>./</code> can execute the script.</p>
  
  <pre><code>[luban@lunbanworks 6] ~ &gt;cat myscript.py
  
      #!/home/luban/Linux/Python/2.7.3/bin/python
      myname="lunban"
  
      print "myname is %s" % myname
  
  [luban@lunbanworks 7] ~ &gt;./myscript.py
  
      myname is luban
  </code></pre>
  
  <p>Why  when I use <code>#!/home/luban/Linux/Python/2.7.3/bin/python</code> at the beginning of myscript.py, <code>./myscript.py</code> can work,</p>
  
  <p>but if I use the wrapper <code>#!/home/luban/bin/python</code> in my python script, use <code>./</code>  to run the script, it cannot not work?</p>
  
  <p>I had many scripts used <code>#!/home/luban/bin/python</code> when I only installed python  under <code>#!/home/luban/</code> for Linux, they can run with <code>./</code>, I don't want to change them,</p>
  
  <p>so, how to let <code>./</code> run the python script If I want to KEEP wrapper <code>#!/home/luban/bin/python</code> as the shebang line? </p>
  
  <hr>
  
  <p>DEIT:</p>
  
  <p><code>./myscript.py</code> can NOT work with the wrapper <code>#!/home/luban/bin/python</code> under <code>CentOS 5.4, Bash 3.2.25</code></p>
  
  <p>today, I have a test under <code>CentOS 6.4, Bash 4.1.2</code>:</p>
  
  <p>I added </p>
  
  <pre><code>echo '$0 =' $0
  echo '${COMMAND_PATH}/${COMMAND} ${1+"$@"} =' ${COMMAND_PATH}/${COMMAND} ${1+"$@"}
  </code></pre>
  
  <p>into the wrapper <code>#!/home/luban/bin/python</code> to track.</p>
  
  <p><code>./myscript.py</code> works with the wrapper <code>#!/home/luban/bin/python</code></p>
  
  <pre><code>[luban@lunbanworks 20] ./myscript.py 
        $0 =  /home/luban/bin/python
        ${COMMAND_PATH}/${COMMAND} ${1+"$@"} =  /home/luban/Linux/Python/2.7.3/bin/python ./myscript.py
        myname is luban
  </code></pre>
  
  <p>So I suppose that it may be a Bash 3.2.25 bug for <code>./</code> when I use the wrapper <code>#!/home/luban/bin/python</code>?</p>