Sunday, November 9, 2025

✨ Mastering Bash Special Characters — The Real Power of Linux Terminal 🔥

🔥 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

SymbolMeaningExample
$Variable / Command outputecho $HOME
#Comment# comment
*Wildcard (match all)*.txt
?Match one characterfile?.log
\Escape characterecho \"hello\"
~Home directorycd ~

✅ Command Execution Operators

SymbolMeaningExample
;Run sequentiallycmd1; cmd2
&&Run if previous successbuild && deploy
||Run if previous failscd logs || mkdir logs
&Run in backgroundsleep 5 &

✅ Pipes & Redirection

SymbolMeaningExample
|Pipe outputls | grep txt
>Output to file (overwrite)echo hi > file.txt
>>Append to fileecho hi >> file.txt
<Redirect inputsort < data.txt

✅ Advanced Redirection

SymbolMeaningExample
<<Heredoccat << EOF
<<<Here-stringcat <<< "Hello"

✅ Test & Grouping

SymbolMeaningExample
[ ]Test[ -f file.txt ]
[[ ]]Advanced test[[ $a == $b ]]
( )Subshell(cd /tmp && ls)
{ }Command block{ echo A; echo B; }

✅ Brace Expansion

PatternMeaningExample
{1..5}Number rangeecho {1..5}
{a,b}Listmv f.{txt,backup}

✅ Special Shell Variables

VariableMeaning
$?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