AnyCompiler

Redirection Aur Heredocs

> ek command ka standard output screen ki jagah ek file mein redirect kar deta hai (use overwrite karte hue), aur 2> specifically standard error ke liye wohi karta hai — yeh dono separate streams hain. Dono mein se kisi ko bhi special file /dev/null mein redirect karna use puri tarah discard kar deta hai, jo un outputs ko silence karne ka standard tareeka hai jin ki aap ko parwah nahi.

ls /nonexistent-path-xyz 2>/dev/null
echo "done"
Output
done

Ek heredoc (<<EOF ... EOF) literal text ki multiple lines ek command ko feed karta hai jaise woh prompt par type ki gayi hon — bina separate file ke inline multi-line text ke liye useful.

cat <<EOF
line one
line two
EOF
Output
line one
line two

Aage: case statements — glob-style patterns se ek value ke against pattern-matching.

Practice exercise

cat ke sath ek heredoc use kar ke, exactly yeh do lines print karein: step one, phir step two.