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

1 points
Created by:

1. Correct header for a bash script


2. Simple bash sh script with .sh header

Filename eg

Code example:


# print to console
echo 'Hello World'

# will wait until user press Enter


Hello World

3. Steps with explanation how to run this example

  1. Create file (any file works with .sh extension)
  2. Open console in the same directory as our
  3. Enter: $ 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 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?


  1. Bash (Unix shell)
  2. Shebang-(Unix)
  3. Shell script
  4. Unix shell
Hey đź‘‹
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.