Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Bash Script – Write Hello World Program

  • Last Updated : 08 Dec, 2021

In this article, we are going to see how to write “hello world” program in Bash script.

The bash script is a text file that contains a set of instructions ( i.e. codes or commands ) that can be executed in the terminal. In any programming language, the first program that we learn to write is ” Hello World “.  

Stepwise Implementation

Step 1: Create an empty file named ” HelloWorld ” in the terminal

We can create an empty file using the following commands:

$ touch HelloWorld.sh

Where:

  • touch : It is used to create an empty file.
  • HelloWorld.sh : HelloWorld is file with .sh extension of unix shell executable file.

Step 2: Open file

Here we will open our created file, using the following commands: 

$ nano HelloWorld.sh

Where:

  • nano : It is used to open files in a text editor ( i.e. GNU nano )

The editor is open, write the following code in a text editor:

#!/bin/sh
# This is bash program to display Hello World
echo " Hello World "

Where:

  • #! : It is known as shebang.
  • /bin/sh: It is the executable path of the system shell.
  • # : It is used to write comments.
  • echo : It is used to display text on the screen.

Step 3: Give permission to execute the script

$ chmod +x HelloWorld.sh

Where:

  • chmod +x : It is used to make file executable.

Step 4: Run the script

$ ./Helloworld.sh  

Output:

Hello World

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!