Courseiva
Automation, Orchestration, and ScriptingeasyMultiple ChoiceObjective-mapped

XK0-006 Automation, Orchestration, and Scripting Practice Question

Which of the following Bash variable expansions will result in the string "Hello World"?

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

${GREETING:-'Hello World'} when GREETING is unset

${var:-default} expands to the value of var if var is set and not null; otherwise, it expands to default. In option C, GREETING is unset, so ${GREETING:-'Hello World'} expands to 'Hello World'. Option A: ${GREETING:+World} with GREETING=Hello expands to 'World' because + uses alternate value when var is set. Option B: ${GREETING:-World} with GREETING=Hello expands to 'Hello' because var is set. Option D: ${GREETING:=World} with GREETING unset assigns 'World' to GREETING and expands to 'World', not 'Hello World'. Therefore, only option C yields 'Hello World'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ${GREETING:+World} when GREETING=Hello

    Why it's wrong here

    This would output 'World' because GREETING is set.

  • ${GREETING:-World} when GREETING=Hello

    Why it's wrong here

    This would output 'Hello' because GREETING is set.

  • ${GREETING:-'Hello World'} when GREETING is unset

    Why this is correct

    Since GREETING is unset, the default value 'Hello World' is used.

  • ${GREETING:=World} when GREETING is unset

    Why it's wrong here

    This would set GREETING to 'World' and output 'World', not 'Hello World'.

About these practice questions

This XK0-006 question is part of Courseiva's 979-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.