CompTIA

XK0-006 practice question 8

CompTIA Linux+ · free question 8 of 20

Question

In the echo "profile-$num-$name" line of a shell script, the variable $num seems to not be expanding during execution. Which of the following notations ensures the value is expanded?
  • A. echo "profile-$(num)-$name"
  • B. echo 'profile-$num-$name'
  • C. echo "profile-`$num`-$name"
  • D. echo "profile-${num}-$name" Correct

Explanation

Braces mark exactly where the variable name begins and ends, so ${num} is expanded as the variable num regardless of the characters around it. $(num) is command substitution and tries to run a command called num, single quotes stop all expansion, and backticks are also command substitution, so they would try to run the variable's value as a command.

Practice the whole free set

Answer all 20 free XK0-006 questions with instant feedback, or unlock all 154 questions with Learn and Exam modes.