writting executable script
October 8th, 2006 mysurface Posted in Bash, chmod, Developer, file, python, sh, which | Hits: 68532 | 7 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
./myscript.py
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?
- Add the path of script interpreter at the first line of your script.
- 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:
#!/usr/bin/python
Then i change mode to executable:
chmod +x myscript.py
For shell script, add this entry:
#!/bin/sh
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







October 8th, 2006 at 6:58 pm
We may use the
envinstead if we don’t know the exact location ofpython:#! /usr/bin/env pythonMore at:
python FAQ, python’s mailling list discussion
September 17th, 2009 at 6:39 am
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.
September 17th, 2009 at 6:41 am
how to compute correlattions among three variables?
December 28th, 2010 at 11:11 pm
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
March 16th, 2012 at 1:56 pm
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
June 3rd, 2012 at 5:55 am
How come you do not have your site viewable in wap format? Can not view anything in my Droid.
June 23rd, 2012 at 2:47 am
There is obviously a bunch to know about this. I believe you made certain nice points in features also.