Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a python program in that I wrote some python code (disk.py). I executed this program using the command python disk.py in a terminal, it worked.

Now I want to execute it using a shell script.

share|improve this question
1  
You mean executing like ./disk.py (wild guess)? If so, you just need to add a suitable hash-bang, i.e. #!/usr/bin/python. If you mean some else, you need to clarify what you are talking about. –  Faheem Mitha Mar 1 at 9:06
    
First, rewrite the program logic in Shell script. Or I'm confused! –  SparKot ॐ Mar 1 at 9:22

2 Answers 2

up vote 1 down vote accepted

To be able to execute as ./disk.py you need two things:

  1. Change the first line to this: #!/usr/bin/env python
  2. Make the script executable: chmod +x disk.py
share|improve this answer
    
why we need to write like this #/usr/bin/env python. what's purpose for env python –  rajcoumar Mar 1 at 9:43
    
@rajcoumar it's more portable this way. In some systems python might be in /usr/bin/python, in others it might be /opt/bin/python. With #!/usr/bin/env python it should work in all systems where python is correctly installed, regardless of its exact location. –  janos Mar 1 at 10:18
    
Thanks for your great information @janos –  rajcoumar Mar 1 at 10:22
    
Isn't it python script rather than shell script ? –  SHW Mar 18 at 8:34

Shell script should be like:

#!/bin/sh
python disk.py
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.