Welcome to the TS Academy Bash Scripting repository! This project is a comprehensive guide designed for the Phoenix cohort to master Linux automation, shell scripting logic, and command-line efficiency.
The scripts are organized by concept to help you progress from basic commands to complex automation logic.
shebang.sh: The essential first line of every script.user-input-p.sh&user-input.sh: Learning how to capture data from users usingread.arguments.sh: How to pass data into scripts using positional parameters ($1,$2, etc.).variable.sh: Defining and using variables effectively.
string/slicing.sh: Techniques for extracting parts of strings (e.g.,${name:0:2}).array.sh: Storing lists of data and accessing them by index or as a whole.
if_basic.sh&if-else.sh: Fundamental "if-then-else" logic.if-elif-else.sh: Handling multiple specific conditions in a sequence.user-check.sh: Validating users against specific criteria.combined-con.sh: Using logical operators (&&,||) to check multiple things at once.case-statement.sh: A cleaner way to handle multiple choices (like a car brand selector).
num-comp.sh: Comparing numbers (-gt,-lt,-eq).string-comparison.sh: Comparing text and checking for empty strings.file-exp.sh&perm-checks.sh: Checking if files exist and verifying permissions (read/write/execute).exit-status.sh: Using$?to determine if the previous command succeeded or failed.
- For Loops:
for_loop.sh(iterating over lists) andprocess-file.sh(automating tasks across multiple files). - While Loops:
while-loop.sh(performing tasks until a condition changes, like a login prompt). - Until Loops:
until-loop.sh(waiting for a specific event, like a server coming back online).
function.sh: The basic syntax for reusable code blocks.clean.sh: A comparison showing how functions make code cleaner and less repetitive.personalized_greeting.sh&extra_args.sh: Passing arguments directly into functions.
git clone https://github.com/ts-academy/bash-script.git
cd bash-scriptBefore running a script, you must give it execution permissions:
chmod +x filename.sh./filename.sh| Operator | Meaning | Use Case |
|---|---|---|
-eq |
Equal to | Numbers |
-ne |
Not equal to | Numbers |
== |
Equal to | Strings |
-z |
Is Empty | Strings |
-f |
Is a regular file | Files |
-d |
Is a directory | Directories |
- Always use a Shebang: Start your scripts with
#!/bin/bash. - Quote your Variables: Use
"$variable"instead of$variableto prevent errors with spaces. - Comment your Code: Use
#to explain what complex lines are doing—it helps your future self! - Check Exit Status: Use
echo $?after a command to see if it worked (0 = Success).
This repository is maintained for the Phoenix Cohort. Our goal is to build world-class DevOps engineers through hands-on practice.
Happy Scripting! 🐧