String Manipulation
Bash mein call karne ke liye koi string methods nahi hote — iske badle, ${...} parameter expansion syntax wahi kaam karta hai. ${#str} length deta hai. ${str^^} uppercase mein convert karta hai aur ${str,,} lowercase mein (ek Bash 4+ feature). ${str/old/new} old ka first match new se substitute karta hai.
script.sh
Khud try karo →str="Hello, World!"
echo "${#str}"
echo "${str^^}"
echo "${str,,}"
echo "${str/World/Bash}"Output
13 HELLO, WORLD! hello, world! Hello, Bash!
Aage: parameter expansion — prefixes aur suffixes strip karna, aur ek unset variable ke liye default value dena.
Practice exercise
str="shell scripting" diya gaya hai, uski length print karo, phir usey fully uppercase mein print karo.