What basically is a bash script? A bash script is a user generated scripts which runs through a bash shell and contains set of commands to serve a specific purpose. So before you may create a complex bash script you must have basic concepts of bash scripting. Here is a small tutorial which describes how to create a "Hello World" bash script. Creating a "Hello World" bash script in Linux requires no previous knowledge of bash scripting. All you need is to create a small script file and a command to execute it.
Follow These Steps To Create Your First Bash Script In Ubuntu
- Open Text Editor by navigating to Applications->Accessories->Text Editor
Now copy and paste the following code in your text editor
- Go to File->Save As or simply use SHIFT+CTRL+S to save the script. In the Name box type helloworld.sh. Choose Desktop from the Save in folder drop down list.
- Click on the Save button.
- Now open Terminal by navigating to Applications->Accessories->Terminal
- Use the following command to know where your bash interpreter is located
- As we have saved the helloworld.sh on our desktop, so first navigate to desktop and then use the following command to make the file executable.
- Use the following command to see the output of the bash script we have created.
# Lets declare a STRING variable
#Using echo command to print value of a variable on screen
chmod +x helloworld.sh
Complete Terminal Log For Hello World Bash Script
Contact Us for News Tips, Corrections and Feedback
jaxov@ubuntu:~$ which bash
jaxov@ubuntu:~$ cd Desktop
jaxov@ubuntu:~/Desktop$ chmod +x helloworld.sh