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.