Challenge - 5 Problems
Return Mastery Badge
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 function call?
Consider the following Bash script. What will be printed when the function is called?
Bash Scripting
myfunc() {
echo "Hello"
return 5
}
myfunc
echo $? # prints the return value of the functionAttempts:
2 left
💡 Hint
Remember that echo prints to standard output, and return sets the exit status.
✗ Incorrect
The function prints "Hello" first. Then the return 5 sets the exit status to 5. The echo $? prints that exit status after the function call.
💻 Command Output
intermediate2:00remaining
What does this script output?
What is the output of this Bash script?
Bash Scripting
func() {
local val=10
echo $val
return 3
}
result=$(func)
echo "$result"
echo $? # exit status of funcAttempts:
2 left
💡 Hint
Check what is captured by command substitution and what is the exit status.
✗ Incorrect
The command substitution captures the echo output "10". The return 3 sets the exit status. echo $? prints 3.
📝 Syntax
advanced2:00remaining
Which option causes a syntax error in a Bash function?
Which of these function definitions will cause a syntax error?
Attempts:
2 left
💡 Hint
Look for missing semicolons or command separators.
✗ Incorrect
Option D misses a semicolon or newline between echo and return, causing syntax error.
🚀 Application
advanced2:00remaining
How to capture both output and return code from a Bash function?
You want to capture the output of a Bash function and also check its return code. Which snippet does this correctly?
Attempts:
2 left
💡 Hint
Remember that $? holds the exit status of the last command.
✗ Incorrect
Option C correctly captures output with $(myfunc) and then saves the exit status with ret=$?.
🧠 Conceptual
expert2:00remaining
What is the difference between return and echo in Bash functions?
Which statement best describes the difference between return and echo in Bash functions?
Attempts:
2 left
💡 Hint
Think about what return and echo do in a shell script.
✗ Incorrect
In Bash, return sets the exit status (a number 0-255), echo prints text to the screen or output stream.