Command Substitution Aur Pipes
| ek command ka output directly next command ke input mein bhej deta hai, bina kisi intermediate variable ke — isi tarah Bash chhoti, single-purpose commands ko ek bade pipeline mein compose karta hai.
Poori pipeline ko $(...) mein wrap karna uska final output ek variable mein capture kar leta hai, quoting lesson wali hi command-substitution syntax — yeh ek pipeline par exactly waise kaam karta hai jaise ek single command par karta hai.
script.sh
Khud try karo →sorted=$(echo -e "banana\napple\ncherry" | sort) echo "$sorted"
Output
apple banana cherry
Aage: redirection and heredocs — output ko file mein bhejna ya discard karna, aur multi-line text inline likhna.
Practice exercise
Lines "banana", "apple", "cherry" (echo -e se, ek line par ek) ko sort se pipe karo, sorted result ko command substitution se ek variable mein capture karo, aur woh variable print karo.