Results

See more...

How To Create "Hello World" Bash Script In Ubuntu (Linux)

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.

Hello World

Hello World

Follow These Steps To Create Your First Bash Script In Ubuntu

  1. Open Text Editor by navigating to Applications->Accessories->Text Editor
    Now copy and paste the following code in your text editor
  2. #!/bin/bash
    # Lets declare a STRING variable
    STRING="Hello World"
    #Using echo command to print value of a variable on screen
    echo $STRING

  3. 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.
  4. Click on the Save button.
  5. Now open Terminal by navigating to Applications->Accessories->Terminal
  6. Use the following command to know where your bash interpreter is located
  7. which bash

  8. 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.
  9. cd Desktop
    chmod +x helloworld.sh

  10. Use the following command to see the output of the bash script we have created.
  11. ./helloworld.sh

Complete Terminal Log For Hello World Bash Script

jaxov@ubuntu:~$ which bash
/bin/bash
jaxov@ubuntu:~$ cd Desktop
jaxov@ubuntu:~/Desktop$ chmod +x helloworld.sh
jaxov@ubuntu:~/Desktop$ ./helloworld.sh
Hello World
jaxov@ubuntu:~/Desktop$

Contact Us for News Tips, Corrections and Feedback

Related posts

0 comments
Leave a message...