Languages
[Edit]
EN

Bash correct header #!/bin/sh - create simple bin sh shell script with .sh code example

1 points
Created by:
marc_so
1014

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

  1. Create file bash_test.sh (any file works with .sh extension)
  2. Open console in the same directory as our bash_test.sh
  3. Enter: $ sh bash_test.sh
  4. We see the same result as on below screenshot with result.
  5. 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

  1. How do I create simple .sh header file in linux?
  2. bin/bash header code example
  3. .sh header code example
  4. #!/bin/sh - simple example of header bash script
  5. How to create correct header of linux shell script?

References

  1. Bash (Unix shell)
  2. Shebang-(Unix)
  3. Shell script
  4. Unix shell
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Bash

Bash - correct header - create simple bin sh shell script with .sh
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join