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:
Another example for shell script:
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?
- 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:
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
Another advantage of adding “sha bang” (#!….) is the script will be recognize by file.
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