61 lines
898 B
Markdown
61 lines
898 B
Markdown
### 📌 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.
|
||
|