EN
Bash correct header #!/bin/sh - create simple bin sh shell script with .sh code example
1
points
1. Correct header for a bash script
#!/bin/sh
2. Simple bash sh script with .sh header
Filename eg bash_test.sh
Code example:
#!/bin/sh
# print to console
echo 'Hello World'
# will wait until user press Enter
read
Output:
Hello World
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
- Enter:
$ 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 bash_test.sh
script:
4. Sh header explanation - Shebang
This header #!/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)
Merged questions
- 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?