Shell Script: Execute a python program from within a shell script


I've tried googling the answer but with no luck.

I need to use my works supercomputer server, but for my python script to run, it must be executed via a shell script.

For example I want to execute

How can this be accomplished?

12/7/2010 1:30:53 PM

Accepted Answer

Just make sure the python executable is in your PATH environment variable then add in your script

python path/to/the/


  • In the file, put this
  • Execute this command to make the script runnable for you : chmod u+x
  • Run it : ./
7/14/2015 1:43:29 PM

Method 1 - Create a shell script:

Suppose you have a python file Create a file called that contains


mark it executable using

$ chmod +x

then run it

$ ./

Method 2 (BETTER) - Make the python itself run from shell:

Modify your script and add this as the first line

#!/usr/bin/env python

mark it executable using

$ chmod +x

then run it

$ ./

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow