Introduction to Bash Scripting (Simple Guide)
Bash scripting is a way to make your computer do a set of commands automatically. Instead of typing commands one by one in the terminal, you can put them into a file and run that file. This saves time and reduces mistakes.
What is Bash?
Bash stands for Bourne Again Shell. It’s the program in Linux that lets you type commands and talk to your computer. You type commands in the terminal, and Bash makes them work.
What is a Bash Script?
A Bash script is simply a text file where you write commands. When you run the script, all those commands run automatically, one after another.
Why Use Bash Scripts?
- To save time by automating tasks
- To avoid typing the same commands again and again
- To make work faster and easier
Creating a Very Simple Bash Script
Step 1: Open a Terminal
Use any Linux terminal (like Ubuntu, Kali, or Termux).
Step 2: Create a New File
nano hello.sh
This opens a new file named hello.sh
in the Nano editor.
Step 3: Write Your Script
#!/bin/bash
echo "Hello, world!"
Explanation:
#!/bin/bash
→ Tells the computer to use Bash to run the file.
echo "Hello, world!"
→ Prints the words “Hello, world!” on the screen.
Step 4: Save and Exit
Press CTRL + X
, then press Y
and Enter
to save.
Step 5: Give Permission to Run
chmod +x hello.sh
Step 6: Run the Script
./hello.sh
You should see this output:
Hello, world!
Conclusion
Bash scripting is like making a to-do list for your computer. Once you write the list (the script), the computer can follow it step-by-step without you typing each command. Start with simple scripts and later you can learn advanced things.