XK0-006 Automation, Orchestration, and Scripting Practice Question
In a bash script, a function is defined to calculate a value. Which TWO of the following are valid ways to return a value from the function to the caller? (Select TWO).
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
echo 42
The return statement sets the exit status (0-255). echo outputs to stdout which can be captured via command substitution. Functions cannot return arbitrary integers directly via return if >255.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
exit 42
Why it's wrong here
exit terminates the entire script, not just the function.
- ✓
echo 42
Why this is correct
Prints 42 to stdout; caller can capture with result=$(function).
- ✓
return 42
Why this is correct
Sets the exit code to 42; caller can check $?.
- ✗
return 'value'
Why it's wrong here
return only accepts integers, not strings.
- ✗
print 42
Why it's wrong here
print is not a standard bash command.
Go deeper
Related to this question
Learn chapter
File Transfer and Remote Access
Key term
Value
Value is the perceived worth, benefit, or usefulness that a service, product, or activity delivers to stakeholders, especially customers and the business.
Key term
Bash script
A Bash script is a text file containing a sequence of commands for the Unix shell Bash, allowing users to automate repetitive tasks and streamline system administration on Linux and macOS.
About these practice questions
One of 979 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.