tags:

views:

72

answers:

3

I previously used to copy Python/Perl scripts to access from my bash script. Duplication is not a good idea I know! Is there a way to call them from bin or libs folder that we have set up?

For instance :

  • My python script resides in /home/ThinkCode/libs/python/script.py

  • My bash script resides in /home/ThinkCode/NewProcess/ProjectA/run.sh

  • Now I want to use/call script.py from run.sh

Thank you!

+3  A: 

Just do python /path/to/my/python/script.py.

Daniel Roseman
+1  A: 

In a bash script, you execute programs the same way you do from the bash command prompt.

/home/ThinkCode/libs/python/script.py

If this doesn't launch the script directly, you may need to add python to the beginning (like this: python /home/ThinkCode/libs/python/script.py) and/or ensure that the script is executable (with chmod +x /home/ThinkCode/libs/python/script.py).

ewall
+4  A: 

Make this the first line of your python script (bash will then know this is a python script and it should be run with python):

#/usr/bin/env python

EDIT: my bad, it should be #!/usr/bin/env python not #!/usr/bin/python. It is better to do it this way.

Then chmod your script with u+x (if not a+x).

Now your python script works as an executable. Your bash script, then, can call it like you'd call any executable.

Umang