0
0
Bash Scriptingscripting~20 mins

Why string manipulation is frequent in Bash Scripting - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Manipulation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is string manipulation common in bash scripts?
In bash scripting, why do we often manipulate strings like filenames, paths, or command outputs?
ABecause string manipulation is the only way to run commands in bash.
BBecause bash scripts cannot work with numbers or files, only strings.
CBecause bash scripts mainly handle text data and need to extract or modify parts of strings to automate tasks.
DBecause bash automatically converts all inputs to strings and ignores other data types.
Attempts:
2 left
💡 Hint
Think about what kind of data bash scripts usually process.
💻 Command Output
intermediate
2:00remaining
Output of string slicing in bash
What is the output of this bash command? filename="report_2024.txt" echo ${filename:7:4}
Bash Scripting
filename="report_2024.txt"
echo ${filename:7:4}
Aport
Btxt
C202
D2024
Attempts:
2 left
💡 Hint
The syntax ${variable:start:length} extracts a substring.
📝 Syntax
advanced
2:00remaining
Correct syntax for replacing substring in bash
Which option correctly replaces the first occurrence of 'cat' with 'dog' in the variable text?
Bash Scripting
text="the cat sat on the cat"
Aecho ${text/cat/dog}
Becho ${text//cat/dog}
Cecho ${text:cat:dog}
Decho ${text:replace(cat,dog)}
Attempts:
2 left
💡 Hint
Use bash parameter expansion for substring replacement.
🔧 Debug
advanced
2:00remaining
Identify the error in string trimming
What is the output of this bash command? path="/home/user/docs/file.txt" echo ${path#*/home/}
Bash Scripting
path="/home/user/docs/file.txt"
echo ${path#*/home/}
Auser/docs/file.txt
Bhome/user/docs/file.txt
CSyntaxError
D/docs/file.txt
Attempts:
2 left
💡 Hint
The # operator removes the shortest match from the start.
🚀 Application
expert
3:00remaining
Extract domain from email using bash string manipulation
Given the variable email="user@example.com", which command extracts only the domain part (example.com)?
Bash Scripting
email="user@example.com"
Aecho ${email%@*}
Becho ${email#*@}
Cecho ${email%%@*}
Decho ${email##*@}
Attempts:
2 left
💡 Hint
Use parameter expansion to remove everything before '@'.