Recall & Review
beginner
What does the
return command do inside a bash function?It stops the function and sends a numeric exit status (0-255) back to the caller. It does NOT send text output.
Click to reveal answer
beginner
How can you send text output from a bash function?
Use
echo inside the function to print text. The caller can capture this output using command substitution.Click to reveal answer
beginner
What is the difference between
return and echo in bash functions?return sends a numeric status code to indicate success or failure.<br>echo sends text output that can be captured or displayed.Click to reveal answer
beginner
Can
return send strings or complex data in bash?No.
return only sends a number (0-255). To send strings, use echo and capture the output.Click to reveal answer
beginner
How do you capture the output of a bash function that uses
echo?Use command substitution like
result=$(my_function). The variable result will hold the echoed text.Click to reveal answer
What does
return 1 inside a bash function mean?✗ Incorrect
return sends a numeric exit status. return 1 means the function ended with status 1 (usually failure).How do you get text output from a bash function?
✗ Incorrect
Only
echo prints text output. return only sends numeric status.What is the valid range of numbers you can use with
return in bash?✗ Incorrect
return status codes are limited to 0-255 in bash.How do you store the text output of a bash function into a variable?
✗ Incorrect
Use command substitution
$( ) to capture output from echo inside the function.If a bash function uses
return 5, what will $? be after calling it?✗ Incorrect
$? holds the exit status of the last command or function, here it will be 5.Explain how
return and echo differ in bash functions and when to use each.Think about what you want to send back: a number or text.
You got /4 concepts.
Describe how to capture the output of a bash function that prints text using echo.
Remember how you capture command output in bash.
You got /3 concepts.