writting executable script

October 8th, 2006 mysurface Posted in Bash, chmod, Developer, file, python, sh, which | Hits: 115326 | 23 Comments »

Shell script (sh), Bash script (bash), Python and perl are all scripting language. By default, to run a scripting file, for example Python script, you need to do this:

python myscript.py

Another example for shell script:

sh myscript.sh

But we make is executable and can execute by running directly like this


If you place your script into directory that exported into your PATH, such as /usr/bin; you can run without specified ./

How to make your script executable that?

  1. Add the path of script interpreter at the first line of your script.
  2. Change mode to executable

Let say I want to make my python script executable, I add this entry at the first line of myscript.py:


Then i change mode to executable:

chmod +x myscript.py

For shell script, add this entry:


You can use “which” to check the real path of the interpreter, like this

which sh

Another advantage of adding “sha bang” (#!….) is the script will be recognize by file.

file myscript.sh

If you do not add “sha bang”, file will display

myscript.sh: ASCII text

But after you add that,

myscript.sh: Bourne shell script text executable

23 Responses to “writting executable script”

  1. We may use the env instead if we don’t know the exact location of python:

    #! /usr/bin/env python

    More at:
    python FAQ, python’s mailling list discussion

  2. how can I write an executable script using the linux that computes summary statistics for the variables x1,x2,and x3. Include: n, no. of missing observations, mean, variance, standard deviation, and minimum and maximum values.

  3. how to compute correlattions among three variables?

  4. Interesting read i think your website is fantastic with top notch content which i like to add to my bookmarks. I’d like to share everyone this new type of app that allows you to spy on other peoples iphone pretty clever if you ask me check out cell phone spy

  5. writting executable script » Linux by Examples I was recommended this website by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are amazing! Thanks! your article about writting executable script » Linux by ExamplesBest Regards Lisa

  6. How come you do not have your site viewable in wap format? Can not view anything in my Droid.

  7. There is obviously a bunch to know about this. I believe you made certain nice points in features also.

  8. Heya i am for the first time here. I found this board and I
    find It truly useful & it helped me out a lot. I hope to give something back and aid others like you
    aided me.

    best rated casinos in southern california [Laurinda]

  9. Hi i am kavin, its my first occasion to commenting anyplace, when i read this piece of writing
    i thought i could also create comment due to this good

  10. If I could come across some more posts like this one, that would be great.

  11. I believe I actually checked out a different post similar to this one in the past. It had the exact same content and is equally well published.

  12. Great write-up. It looks like much time and energy went towards this one.

  13. It is evident that this blog post is one of the best I’ve found today. It’s also evident the person who’s page this is put a whole lot of work in it. Great job!

  14. This unique page is very interesting. I may definately be coming back to your site.

  15. xavier4116 Says:

    It is evident that the following blog post is probably the best I have found today. It’s also evident the person who’s page this is put much work in it. Great work!

  16. You can hardly find posts like this anymore. I recall when you could find one or two posts like this in minutes but now it’s much harder.

  17. denise9249 Says:

    This content is very engaging. I will certainly be returning your website.

  18. elizbeth1486 Says:

    This page is very interesting. I may certainly be returning your website.

  19. detox fast Says:

    Very good content when compared to some of the similar posts I’ve checked out. Carry on the nice work.

  20. georgie1929 Says:

    It is always just so exciting to discover good information such as this considering the irrelevant content that’s out there. I mean, you can definitely tell that much time and patience with into this. Do you work with content writers or do you compose your own content?

  21. beat drug test Says:

    This is easily some of the best information I’ve stumbled on today. It’s not necessarily what I was looking for nonetheless it certainly got my attention. I’m glad I took the time to look it over.

  22. Great looking website. Presume you did a bunch of your ownyour very own html coding
    nhl 17 http://www.gta-five-forum.com/blog-e31345-fifa-points-To-Lose-Weight.html

  23. Hi there, its good piece of writing about media print, we all be aware of media is a great source of facts.

Leave a Reply