EN
Bash correct header #!/bin/sh - create simple bin sh shell script with .sh code example
1 points
xxxxxxxxxx
1
Filename eg bash_test.sh
Code example:
xxxxxxxxxx
1
2
3
# print to console
4
echo 'Hello World'
5
6
# will wait until user press Enter
7
read
Output:
xxxxxxxxxx
1
Hello World
- 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:
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)