From 2e8f53ca271f5b17d5df4feaa4b73290c59e2eb6 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 3 Aug 2025 00:33:05 +0330 Subject: [PATCH] for doc bash script --- .../Kubernetes/workloads/14-Ingress.md | 2 + Linux/Bash Script/9-For.md | 126 ++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 Containerization & Orchestration/Kubernetes/workloads/14-Ingress.md diff --git a/Containerization & Orchestration/Kubernetes/workloads/14-Ingress.md b/Containerization & Orchestration/Kubernetes/workloads/14-Ingress.md new file mode 100644 index 0000000..5b67d86 --- /dev/null +++ b/Containerization & Orchestration/Kubernetes/workloads/14-Ingress.md @@ -0,0 +1,2 @@ +traffic input --> ingress +traffic output --> egress diff --git a/Linux/Bash Script/9-For.md b/Linux/Bash Script/9-For.md index e69de29..f626d61 100644 --- a/Linux/Bash Script/9-For.md +++ b/Linux/Bash Script/9-For.md @@ -0,0 +1,126 @@ +# Bash `for` Loop Cheat Sheet + +A clear and concise reference for using `for` loops in Bash, with syntax variations, examples, and best practices. + +--- + +## 1. Basic `for` Loop (List Iteration) + +Iterates over a fixed list of items. + +**Syntax:** + +```bash +for VARIABLE in ITEM1 ITEM2 ITEM3 ... +do + commands +DONE +done +``` + +**Example:** + +```bash +for color in red green blue +do + echo "Color: $color" +done +``` + +*Output:* + +``` +Color: red +Color: green +Color: blue +``` + +--- + +## 2. Numeric Iteration Using a List + +When you explicitly list out numbers. + +**Example:** + +```bash +for i in 1 2 3 4 5 +do + echo "Number: $i" +done +``` + +*Output:* + +``` +Number: 1 +Number: 2 +Number: 3 +Number: 4 +Number: 5 +``` + +--- + +## 3. C-style `for` Loop (Arithmetic) + +Similar to loops in C-style languages: initialize, condition, increment. + +**Syntax:** + +```bash +for (( init; condition; increment )) +do + commands +ndone +``` + +**Example:** + +```bash +for (( i=0; i<5; i++ )) +do + echo "Index: $i" +done +``` + +*Output:* + +``` +Index: 0 +Index: 1 +Index: 2 +Index: 3 +Index: 4 +``` + +--- + +## 4. Looping Over Files (Globbing) + +Use shell glob patterns to iterate over matching filenames. + +**Example:** + +```bash +for file in *.txt +do + echo "Found text file: $file" +done +``` + +``` +# If the directory contains a.txt and notes.txt, output might be: +Found text file: a.txt +Found text file: notes.txt +``` + +--- + +## Summary + +| Style | Purpose | Notes | +| ----------------- | ------------------------------------------ | ------------------------------------- | +| `for var in list` | Iterate over a static list or glob results | Most common in shell scripting | +| `for (( ... ))` | Numeric / arithmetic loops | C-style syntax, powerful for counters | +