Bird
0
0

What will be the output of this script?

medium📝 Command Output Q4 of 15
Bash Scripting - Functions
What will be the output of this script?
func() {
  echo "Hi"
  return 4
}
func
echo $?
AHi 4
B4 Hi
CHi 0
D4 0
Step-by-Step Solution
Solution:
  1. Step 1: Analyze function behavior

    The function prints "Hi" using echo, then returns status 4.
  2. Step 2: Analyze script output

    Calling func prints "Hi". Then echo $? prints the last return status, which is 4.
  3. Final Answer:

    Hi 4 -> Option A
  4. Quick Check:

    Echo output + return status = A [OK]
Quick Trick: Echo prints text; $? shows last return code [OK]
Common Mistakes:
MISTAKES
  • Expecting return value to print automatically
  • Confusing order of output
  • Assuming return affects echo output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes