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:
- Open a text editor and copy the script into a new file. Save it with a
.sh
extension, such ashello.sh
. - Open a terminal or command prompt.
- Navigate to the directory where you saved the
hello.sh
script. - Make the script executable by running the command:
chmod +x hello.sh
. This grants the script execution permission. - 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.