Day 4: Shell Scripting Basics for DevOps Engineers π
Hello DevOps enthusiasts! π Welcome to Day 4 of the #90DaysOfDevOps challenge. Today, we're diving into shell scripting basics, a crucial skill for automation in DevOps.
Understanding the Basics π
What is Kernel?
The kernel is the core component of an operating system that manages:
- System resources
- Hardware communication
- Process management
- Memory management
What is Shell?
Shell is an interface between users and the kernel, allowing us to:
- Execute commands
- Automate tasks
- Manage system resources
- Process user inputs
Task Solutions π»
1. Print Challenge Message
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"
2. Take User Input and Arguments
#!/bin/bash
# Read user input
read -p "Enter your name: " username
echo "Hello, $username!"
# Display script arguments
echo "Script arguments: $@"
3. Compare Two Numbers
#!/bin/bash
read -p "Enter first number: " num1
read -p "Enter second number: " num2
if [ $num1 -gt $num2 ]; then
echo "$num1 is greater than $num2"
elif [ $num1 -lt $num2 ]; then
echo "$num1 is less than $num2"
else
echo "Both numbers are equal"
fi
Key Components Used π§
-
Shebang (
#!/bin/bash
)- Tells system to use bash interpreter
-
Echo Command
- Displays text/variables
-
Read Command
- Captures user input
-
If-Else Statement
- Controls program flow
- Compares values
-
Variables
- Store and manipulate data
Key Takeaways π‘
- Shell scripts automate repetitive tasks
- Basic constructs enable powerful automation
- User input makes scripts interactive
- Proper script structure is important
Bash #DevOps #Automation #Linux #90DaysOfDevOps
This is Day 4 of my #90DaysOfDevOps journey. Keep learning and automating!