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
# 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.
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.
Now its time to execute our program.
Type chmod +x file_name. Here filename is helloworld.sh. And then press enter.
After you press enter, your cursor will come on the next line as shown in below image.
Now type ./file_name and then enter
You can see below image that hello world is printed successfully 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:
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Page Views :
Published Date :