diff --git a/Linux/Bash Script/1-Echo.md b/Linux/Bash Script/1-Echo.md new file mode 100644 index 0000000..fc78d07 --- /dev/null +++ b/Linux/Bash Script/1-Echo.md @@ -0,0 +1,60 @@ +### πŸ“Œ Echo Basic Usage + +```bash +echo Hello, world! +``` + +**Output:** + +``` +Hello, world! +``` + +--- + +### πŸ’‘ Common Use Cases + +1. **Print plain text:** + + ```bash + echo This is a message + ``` + +2. **Print environment variables (Linux/macOS):** + + ```bash + echo $HOME + ``` + +3. **Print environment variables (Windows):** + + ```cmd + echo %USERNAME% + ``` + +4. **Write to a file:** + + ```bash + echo "Log entry" >> logfile.txt + ``` + +5. **Suppress newline (Unix/Linux):** + + ```bash + echo -n "No newline" + ``` + +6. **Use with escape characters (Unix/Linux):** + + ```bash + echo -e "Line1\nLine2" + ``` + +--- + +### ⚠️ Notes + +* On **Unix-like systems**, `echo` is a shell builtin (e.g., in `bash`, `sh`). +* On **Windows**, it’s a command in `cmd.exe`. +* Behavior may vary slightly between environments. For complex text handling, consider using `printf` instead in Unix/Linux. + diff --git a/Linux/Bash Script/2-Operators.md b/Linux/Bash Script/2-Operators.md new file mode 100644 index 0000000..d97fa74 --- /dev/null +++ b/Linux/Bash Script/2-Operators.md @@ -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 +``` +