## Introduction to Bash Scripting

Bash (Bourne Again SHell) is the default shell on most Linux distributions. Learning bash scripting transforms you from a manual command-runner into an automation engineer.

## Your First Bash Script

“`
#!/bin/bash
echo “Hello, HowToHub!”
“`

Save this as `hello.sh`, then make it executable: `chmod +x hello.sh`.

## Variables and User Input

“`
#!/bin/bash
name=”HowToHub”
echo “Welcome to $name”
read -p “Enter your name: ” user
echo “Hello, $user!”
“`

## Conditional Statements

“`
#!/bin/bash
read -p “Enter a number: ” num
if [ $num -gt 10 ]; then
echo “Number is greater than 10”
elif [ $num -eq 10 ]; then
echo “Number is exactly 10”
else
echo “Number is less than 10”
fi
“`

## Loops

“`
#!/bin/bash
for i in {1..5}; do
echo “Iteration $i”
done

count=1
while [ $count -le 5 ]; do
echo “Count: $count”
((count++))
done
“`

## Functions

“`
#!/bin/bash
greet() {
local name=”$1″
echo “Hello, $name!”
}
greet “Linux User”
“`

## Real-World Example: Backup Script

“`
#!/bin/bash
backup_dir=”/backup/$(date +%Y%m%d)”
mkdir -p “$backup_dir”
tar -czf “$backup_dir/home.tar.gz” /home/user
echo “Backup completed: $backup_dir”
“`

## Conclusion

Bash scripting is an essential skill for any Linux administrator. Start with simple scripts and gradually build complex automation workflows.