Skip to content

HilRosie/bash-script

 
 

Repository files navigation

🚀 Phoenix Bash Scripting Academy

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.

📂 Repository Structure

The scripts are organized by concept to help you progress from basic commands to complex automation logic.

1. The Basics

  • shebang.sh: The essential first line of every script.
  • user-input-p.sh & user-input.sh: Learning how to capture data from users using read.
  • arguments.sh: How to pass data into scripts using positional parameters ($1, $2, etc.).
  • variable.sh: Defining and using variables effectively.

2. Data Manipulation

  • 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.

3. Logic & Conditionals (/conditionals)

  • 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).

4. Expressions & Checks (/expressions)

  • 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.

5. Loops & Iteration (/loops)

  • For Loops: for_loop.sh (iterating over lists) and process-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).

6. Functions (/functions)

  • 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.

🛠 How to Use These Scripts

1. Clone the Repository

git clone https://github.com/ts-academy/bash-script.git
cd bash-script

2. Make a Script Executable

Before running a script, you must give it execution permissions:

chmod +x filename.sh

3. Run the Script

./filename.sh

📝 Key Concepts for Students

Common Operators Reference

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

Best Practices

  1. Always use a Shebang: Start your scripts with #!/bin/bash.
  2. Quote your Variables: Use "$variable" instead of $variable to prevent errors with spaces.
  3. Comment your Code: Use # to explain what complex lines are doing—it helps your future self!
  4. Check Exit Status: Use echo $? after a command to see if it worked (0 = Success).

🎓 About TS Academy

This repository is maintained for the Phoenix Cohort. Our goal is to build world-class DevOps engineers through hands-on practice.

Happy Scripting! 🐧

About

bash-script TSACADEMY

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Shell 100.0%