How to create a script in bash.

How To Create A Script In Bash.

Bash is a popular scripting language used in Unix-based operating systems. It is known for its simplicity and powerful features. In this article, we will walk you through the process of writing a basic “Hello, World!” script in Bash.

 

Step 1: Create a new Bash script file

  • Open a linux text editor .
    Create a new file and give it a suitable name, such as “hello_world.sh”. The “.sh” extension is commonly used for Bash scripts.

 

Step 2: Write the script.

  • 3. In the newly created file, type the following code:

    #!/bin/bash
    echo "Hello, World!"
  • Let’s break down the code:
    The first line, “#!/bin/bash”, is called a shebang. It tells the system that this script should be executed using the Bash interpreter.

  • The second line, “echo “Hello, World!””, is the actual command that prints the text “Hello, World!” to the console.

 

Step 3: Save and make the script executable 5. Save the file.

  • Open a terminal or command prompt.

  • Navigate to the directory where you saved the script file using the “cd” command.

  • Make the script file executable by running the following command:

  • chmod +x hello_world.sh

 

Step 4: Run the script.

  • Run the script by typing its name:

./hello_world.sh

 

Conclusion:

Congratulations! You have successfully written and executed your first “Hello, World!” script in Bash. This simple example demonstrates the basic structure of a Bash script and how to print output to the console.