Bird
0
0

How can you capture the text output of a bash function greet that uses echo inside, and store it in a variable msg?

hard🚀 Application Q15 of 15
Bash Scripting - Functions
How can you capture the text output of a bash function greet that uses echo inside, and store it in a variable msg?
Amsg=$(greet)
Bmsg=return greet
Cmsg=`return greet`
Dmsg=echo greet
Step-by-Step Solution
Solution:
  1. Step 1: Understand capturing function output

    To capture text output from a function that uses echo, use command substitution: $(function_name).
  2. Step 2: Identify correct syntax

    msg=$(greet) runs greet and stores its echo output in msg. Other options misuse return or echo.
  3. Final Answer:

    msg=$(greet) -> Option A
  4. Quick Check:

    Use $(function) to capture echo output [OK]
Quick Trick: Use $(function) to capture echo output in variable [OK]
Common Mistakes:
MISTAKES
  • Using return instead of command substitution
  • Assigning echo command directly to variable
  • Using backticks incorrectly with return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes