Our Knowledge Base provides step-by-step guides, troubleshooting tips, and expert insights to help you manage VPS, dedicated servers, domains, DDoS protection, and more — all designed to make your experience with us fast, secure, and stress-free.
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.
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.
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.
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
Run the script by typing its name:
./hello_world.sh
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.