Run python script with ./

Discussion in 'Python' started by LubanWorks, Apr 5, 2013.

  1. LubanWorks

    LubanWorks Guest

    Hi all,
    I installed two python 2.7.3 into my home directory

    one is for Linux: /home/luban/*Linux*/Python/2.7.3
    another is for Solaris: /home/luban/*SunOS*/Python/2.7.3

    then I create a wrapper named "python" in /home/luban/bin to call the
    different python when I am working on different systems.

    [luban@lunbanworks 1] ~ > cat /home/luban/bin/python

    #!/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>&2

    exit 1

    fi

    [luban@lunbanworks 2] ls -l /home/luban/bin/python
    -rwxrwxr-x 1 luban lunban 221 Apr 5 19:11 python*


    I use below script to test the wrapper /home/luban/bin/python

    [luban@lunbanworks 3]* ~ > *cat myscript.py
    #!/home/luban/bin/python

    myname="lunban"

    print "myname is %s" % myname

    [luban@lunbanworks 4]* *chmod +x myscript.py

    I want to use ./ run myscript.py

    [luban@lunbanworks 5] ~ >./myscript.py
    myname=luban: Command not found.
    lpr: Unable to access "myname" - No such file or directory


    use /home/luban/bin/python myscript.py can work:*

    *[luban@lunbanworks 5] ~ > */home/luban/bin/python myscript.py*
    myname is luban


    After I *change the shebang line to
    #!/home/luban/Linux/Python/2.7.3/bin/python, use ./ can execute the script.
    *
    [luban@lunbanworks 6] *~ >*cat myscript.py
    #!/home/luban/Linux/Python/2.7.3/bin/python
    myname="lunban"

    print "myname is %s" % myname

    [luban@lunbanworks 7] *~ >*./myscript.py
    myname is luban


    My question is:

    Why when I use #!/home/luban/Linux/Python/2.7.3/bin/python at the
    beginning of myscript.py, *./*myscript.py can work,

    but if I use the wrapper #!/home/luban/bin/python in my python script, use *
    ../* to run the script, it cannot not work?


    I had many scripts used #!/home/luban/bin/python when I only installed
    python under #!/home/luban/ for Linux, they can run with ./, I don't want
    to change them,

    so, how to let ./ run the python script If I want to *KEEP* wrapper
    #!/home/luban/bin/python as the shebang line?


    Best Regards,
    Luban
    LubanWorks, Apr 5, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    460
  2. Replies:
    1
    Views:
    317
    Larry Bates
    Dec 14, 2006
  3. sophie_newbie

    Error when python script run as cgi script

    sophie_newbie, Oct 21, 2007, in forum: Python
    Replies:
    3
    Views:
    587
    Dennis Lee Bieber
    Oct 22, 2007
  4. Replies:
    1
    Views:
    466
    Gabriel Genellina
    Apr 7, 2008
  5. Replies:
    9
    Views:
    944
    Paddy O'Loughlin
    Feb 27, 2009
Loading...

Share This Page