Recall & Review
beginner Click to reveal answer
What does the
unset command do in bash scripting?The
unset command removes a variable or function from the shell environment, making it no longer available or defined.beginner Click to reveal answer
How do you unset a variable named
myVar in bash?Use the command
unset myVar to remove the variable myVar from the environment.beginner Click to reveal answer
True or False: After unsetting a variable, trying to access it will return an empty value.
True. Once a variable is unset, it no longer exists, so accessing it returns an empty string or nothing.
intermediate Click to reveal answer
Can
unset be used to remove functions in bash?Yes. Using
unset -f functionName removes the function named functionName from the shell.beginner Click to reveal answer
What happens if you try to unset a variable that does not exist?
Nothing bad happens.
unset silently ignores variables that do not exist, so no error is shown.What is the correct command to remove a variable named
temp in bash?✗ Incorrect
The
unset command is used to remove variables in bash.After running
unset myVar, what will echo $myVar output?✗ Incorrect
Once unset, the variable no longer exists, so echo outputs an empty line.
How do you unset a function named
greet in bash?✗ Incorrect
Use
unset -f functionName to remove a function.What happens if you unset a variable that does not exist?
✗ Incorrect
Unset silently ignores non-existing variables without error.
Which of these is NOT a valid use of
unset?✗ Incorrect
There is no
-u option for unset; variables are unset without flags.Explain how to remove a variable and a function in bash using
unset.Think about the difference between variables and functions.
You got /3 concepts.
What happens when you try to access a variable after unsetting it? Why is this useful in scripts?
Consider how unsetting cleans up your environment.
You got /3 concepts.
