1. Correct header for a bash script
2. Simple bash sh script with .sh header
Filename eg bash_test.sh
#!/bin/sh # print to console echo 'Hello World' # will wait until user press Enter read
3. Steps with explanation how to run this example
- Create file bash_test.sh (any file works with .sh extension)
- Open console in the same directory as our bash_test.sh
$ sh bash_test.sh
- We see the same result as on below screenshot with result.
- If you want to exit script press Enter.
Screenshot with result of
4. Sh header explanation - Shebang
#!/bin/sh at the beginning of the sh file in Unix is called - 'Shebang'.
The purpose of this header:
Shebang is used to detect what interpreter will be used to run the script.
Most popular shebang:
#!/bin/sh – Execute the file using the Bourne shell, or a compatible shell
#!/usr/bin/env python – Execute with a Python interpreter
Read more about Shebang on wikipedia - Shebang-(Unix)
- How do I create simple .sh header file in linux?
- bin/bash header code example
- .sh header code example
- #!/bin/sh - simple example of header bash script
- How to create correct header of linux shell script?