Challenge - 5 Problems
String Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Bash script?
Consider the following Bash script that manipulates string variables. What will it print?
Bash Scripting
name="Alice" welcome="Hello, $name!" echo "$welcome"
Attempts:
2 left
💡 Hint
Remember how Bash replaces variables inside double quotes.
✗ Incorrect
In Bash, variables inside double quotes are expanded to their values. So $name becomes Alice inside the string.
💻 Command Output
intermediate2:00remaining
What does this Bash script output when using single quotes?
Look at this script and decide what it prints:
Bash Scripting
name='Bob' welcome='Hello, $name!' echo "$welcome"
Attempts:
2 left
💡 Hint
Single quotes prevent variable expansion in Bash.
✗ Incorrect
Single quotes treat everything literally, so $name is not replaced by its value.
📝 Syntax
advanced2:00remaining
Which option correctly concatenates two strings in Bash?
You want to join two string variables, first="Good" and second="Morning". Which command correctly concatenates them into greeting?
Bash Scripting
first="Good" second="Morning"
Attempts:
2 left
💡 Hint
In Bash, string concatenation is done by placing variables side by side inside quotes.
✗ Incorrect
Option A joins the two variables without spaces or operators, producing 'GoodMorning'.
🔧 Debug
advanced2:00remaining
Why does this Bash script produce an error?
This script tries to assign a string with spaces to a variable but fails. Identify the cause.
Bash Scripting
greeting=Hello World
echo "$greeting"Attempts:
2 left
💡 Hint
Think about how Bash treats spaces in assignments.
✗ Incorrect
Without quotes, Bash treats 'Hello' and 'World' as separate commands or arguments, causing an error.
🚀 Application
expert3:00remaining
What is the value of 'result' after running this script?
Given the script below, what is the value of the variable 'result'?
Bash Scripting
text=" Bash scripting " trimmed="${text##*( )}" result="${trimmed%%*( )}" echo "$result"
Attempts:
2 left
💡 Hint
Look up how parameter expansion with ## and %% works for trimming spaces.
✗ Incorrect
The script uses Bash parameter expansion to trim leading and trailing spaces from the string.