Challenge - 5 Problems
Unset Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output after unsetting a variable?
Consider the following Bash script snippet:
What will be the output when this script runs?
var="Hello" unset var echo "$var"
What will be the output when this script runs?
Bash Scripting
var="Hello" unset var echo "$var"
Attempts:
2 left
💡 Hint
After unsetting, the variable no longer exists.
✗ Incorrect
The unset command removes the variable from the environment. Echoing an unset variable produces an empty line.
💻 Command Output
intermediate2:00remaining
What happens when unsetting an array element?
Given this Bash code:
What is the output?
arr=(one two three)
unset arr[1]
echo "${arr[@]}"What is the output?
Bash Scripting
arr=(one two three) unset arr[1] echo "${arr[@]}"
Attempts:
2 left
💡 Hint
Unsetting an array element removes it, shifting does not happen.
✗ Incorrect
Unsetting arr[1] removes the second element 'two'. The remaining elements are 'one' and 'three'.
📝 Syntax
advanced2:00remaining
Which option correctly unsets multiple variables in one command?
Select the correct Bash command to unset variables var1, var2, and var3 at once.
Attempts:
2 left
💡 Hint
The unset command accepts multiple variable names separated by spaces.
✗ Incorrect
Option D uses the correct syntax: 'unset' followed by variable names separated by spaces.
🔧 Debug
advanced2:00remaining
Why does this unset command fail?
Given this script snippet:
Why does the variable still print 'data' after unsetting?
myvar="data" unset "$myvar" echo "$myvar"
Why does the variable still print 'data' after unsetting?
Attempts:
2 left
💡 Hint
Check what the argument to unset actually is.
✗ Incorrect
Using quotes causes the variable's value to be passed to unset, so it tries to unset a variable named 'data', which does not exist.
🚀 Application
expert2:00remaining
How many variables remain after this script runs?
Consider this Bash script:
How many variables named var1, var2, var3, var4, var5 exist after running?
var1=10 var2=20 var3=30 unset var2 var4=40 unset var5
How many variables named var1, var2, var3, var4, var5 exist after running?
Attempts:
2 left
💡 Hint
Unset removes variables if they exist; unsetting a non-existent variable does nothing.
✗ Incorrect
var2 is unset, var5 was never set, so only var1, var3, and var4 remain.