Bash Scripting: Hello world

Sure! Here’s a simple “Hello, World!” example in Bash scripting:


#!/bin/bash
echo "Hello, World!"

Let’s break down the script:

  • The first line #!/bin/bash is called the shebang and specifies the path to the Bash interpreter. It tells the system that this script should be executed using Bash.
  • The second line echo "Hello, World!" is the actual command in the script. echo is a command used to print text to the terminal. In this case, it prints the string “Hello, World!”.

To run this script:

  1. Open a text editor and copy the script into a new file. Save it with a .sh extension, such as hello.sh.
  2. Open a terminal or command prompt.
  3. Navigate to the directory where you saved the hello.sh script.
  4. Make the script executable by running the command: chmod +x hello.sh. This grants the script execution permission.
  5. Finally, run the script by typing ./hello.sh and pressing Enter.

You should see the output Hello, World! printed in the terminal. Congratulations! You’ve successfully executed your first Bash script.

Leave a Comment

Your email address will not be published. Required fields are marked *