🔥 Master Bash Special Characters — Power of Linux Terminal
If you work in Linux, DevOps, Cloud, Cyber Security, or Automation, Bash special characters are your superpower.
These symbols control execution, variables, redirection, scripting logic, and automation. Here is the complete cheat-sheet 👇
✅ Basic Bash Symbols
| Symbol | Meaning | Example |
| $ | Variable / Command output | echo $HOME |
| # | Comment | # comment |
| * | Wildcard (match all) | *.txt |
| ? | Match one character | file?.log |
| \ | Escape character | echo \"hello\" |
| ~ | Home directory | cd ~ |
✅ Command Execution Operators
| Symbol | Meaning | Example |
| ; | Run sequentially | cmd1; cmd2 |
| && | Run if previous success | build && deploy |
| || | Run if previous fails | cd logs || mkdir logs |
| & | Run in background | sleep 5 & |
✅ Pipes & Redirection
| Symbol | Meaning | Example |
| | | Pipe output | ls | grep txt |
| > | Output to file (overwrite) | echo hi > file.txt |
| >> | Append to file | echo hi >> file.txt |
| < | Redirect input | sort < data.txt |
✅ Advanced Redirection
| Symbol | Meaning | Example |
| << | Heredoc | cat << EOF |
| <<< | Here-string | cat <<< "Hello" |
✅ Test & Grouping
| Symbol | Meaning | Example |
| [ ] | Test | [ -f file.txt ] |
| [[ ]] | Advanced test | [[ $a == $b ]] |
| ( ) | Subshell | (cd /tmp && ls) |
| { } | Command block | { echo A; echo B; } |
✅ Brace Expansion
| Pattern | Meaning | Example |
| {1..5} | Number range | echo {1..5} |
| {a,b} | List | mv f.{txt,backup} |
✅ Special Shell Variables
| Variable | Meaning |
| $? | Last command status |
| $$ | Process ID |
| $! | Last background PID |
| $@ | All arguments |
| $# | Argument count |
🎯 Example Script
#!/bin/bash
if [[ -f "$1" ]]; then
grep "error" "$1" >> logs.txt && echo "Logged ✅"
else
echo "File not found ❌" && exit 1
fi
#linux #bash #devops #shellscripting #cloud #sysadmin #automation
No comments:
Post a Comment