AnyCompiler

Redirection Aur Heredocs

> ek command ka standard output screen ki jagah ek file mein redirect kar deta hai (usey overwrite karte hue), aur 2> specifically standard error ke liye wahi karta hai — yeh dono separate streams hain. Dono mein se kisi ko bhi special file /dev/null mein redirect karna usey poori tarah discard kar deta hai, jo un outputs ko silence karne ka standard tareeka hai jinki aapko parwaah 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 saath ek heredoc use karke, exactly yeh do lines print karo: step one, phir step two.