Articles

Hello World in Shell Script

Hello World in Shell Script


In this shell script article we are going to learn:

  • shell script to print hello world in linux
  • important linux commands like vi, echo, chmod required to print hello world in linux

Shell Script is a command based language i.e list of commands given by the user and it executes one by one. File manipulation, program execution, and printing text are typical operations performed by it.

 

Points to note before we start

  • At first clear your screen to have clean and fresh terminal.
  • You can either directly print Hello World or store it in a variable which is given by user and then print it.
  • You should save program and give directory where your code will be saved.
  • Use execution command to give permission to execute code otherwise it will show error - permission denied or not given.
  • Coder should use '#' to make a comment just like we use '//' in C, C++ and Java to make comments.

 

Print hello world in shell script

#!/bin/sh
# This is a comment!
echo "Hello World"
# after save the code use chmod 755 file_name.
#insead of 755, you can use +x means to give permission for execution.
#or you can directly use bash file_name

If you are using Linux os, you can directly goto terminal and run.

But if you are using windows or mac os, install vim editor, cyg to comile and run all shell script program. Here I am using cygwin in win os.

 

Shell script Hello World compile steps

First create a file as we do in hard disk or you can directly create file via terminal. I use vi command to 'vi helloworld.sh' where helloworld.sh is file name. Once typed press enter.

hello world in shell script

After above step, press i to insert your code and then type your code. After writing, press esc key and then type ':wq' to save and quit.

hello world in shell script or unix or linux

Now its time to execute our program.

Type chmod +x file_name. Here filename is helloworld.sh. And then press enter.

hello world in shell script

After you press enter, your cursor will come on the next line as shown in below image.

hello world in shell script

Now type ./file_name and then enter

 

hello world in linux

You can see below image that hello world is printed successfully in shell script.

hello world in shell script

 

Explanation to hello world in shell script

  • 'echo' is used to print helloworld.
  • 'vi' is used to create file.
  • 'chmod +x file_name' or 'chmod 755 file_name' is used to give permission for execution.
  • './file_name' is used to execute program.

You can see my video tutorial below to understand hello world in shell script:

 


Shell Script Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Suraj Maity
Page Views :    Published Date : Jan 07,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!