echo and opreators

This commit is contained in:
2025-07-07 20:13:03 +03:30
parent bbb5e2f7c2
commit 7f69a7a878
2 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
# 🖥️ Bash Opreators
A quick reference guide to essential bash command operators and their usage.
---
## `>` — **Write to File (Overwrite)**
This operator **creates a new file** or **overwrites** the contents of an existing file.
```bash
echo "Hi" > file1
```
📄 *Creates* `file1` and writes `"Hi"` into it. If `file1` already exists, its content is replaced.
---
## `>>` — **Append to File**
Adds content to the **end of an existing file** without deleting what's already there.
```bash
echo "Hi" >> file1
```
📝 *Appends* `"Hi"` to the end of `file1`.
---
## `&&` — **AND Operator**
Runs the **second command only if the first succeeds**.
```bash
apt update && apt upgrade
```
🔗 `apt upgrade` runs only if `apt update` completes successfully.
---
## `;` — **Run Multiple Commands**
Executes **commands sequentially**, regardless of success or failure.
```bash
echo "Hi" > file1 ; cat file1
```
🔄 Both commands are executed one after the other.
---
## `*` — **Wildcard (All Matching Files)**
Matches **all files** that meet the pattern.
```bash
cat file*
```
🌐 Displays the contents of all files starting with `file`.
---
## `[ ... ]` — **Specific Character Matching**
Reads files that match specific characters at the position defined in brackets.
```bash
cat file[1,2,3]
```
📚 Reads `file1`, `file2`, and `file3` (if they exist). Equivalent to:
```bash
cat file1 file2 file3
```