0
0
Bash Scriptingscripting~20 mins

String variables in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Variable Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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"
AHello, !
BHello, $name!
CHello, Alice!
Dname
Attempts:
2 left
💡 Hint
Remember how Bash replaces variables inside double quotes.
💻 Command Output
intermediate
2: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"
AHello, !
BHello, $name!
CHello, Bob!
Dname
Attempts:
2 left
💡 Hint
Single quotes prevent variable expansion in Bash.
📝 Syntax
advanced
2: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"
Agreeting="$first$second"
Bgreeting=$first + $second
Cgreeting=$first.$second
Dgreeting="$first + $second"
Attempts:
2 left
💡 Hint
In Bash, string concatenation is done by placing variables side by side inside quotes.
🔧 Debug
advanced
2: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"
ABecause the variable is read-only
BBecause the variable name is invalid
CBecause echo cannot print variables
DBecause the string with spaces is not quoted
Attempts:
2 left
💡 Hint
Think about how Bash treats spaces in assignments.
🚀 Application
expert
3: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"
ABash scripting
Bgnitpircs hsaB
Cscripting
Dash scripting
Attempts:
2 left
💡 Hint
Look up how parameter expansion with ## and %% works for trimming spaces.