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/bashis 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.
echois 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
.shextension, such as
- Open a terminal or command prompt.
- Navigate to the directory where you saved the
- 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.shand pressing Enter.
You should see the output
Hello, World! printed in the terminal. Congratulations! You’ve successfully executed your first Bash script.