ACE-P-ALE1-04 practice question 9 of 35

In shell scripting, what are backticks, or backwards single quote marks, used for?

Full set: 100 questions
Answer options
A: Shell escapes
B: Variable dereference
C: Command substitution Correct answer
D: Output formatting
Correct Answer:
C. Command substitution
Explanation

In shell scripting, backticks ( ) are used for command substitution. This is a mechanism where the shell executes the command enclosed within the backticks and replaces the backticked expression with the standard output of that command. For example, if you execute currentdir=pwd, the shell first runs the pwd command, captures its output (e.g., /home/user), and then assigns this string to the currentdir variable. The $(...)` syntax is a more modern and generally preferred alternative that offers better nesting and readability.

Why Incorrect

A. Shell escapes are performed using the backslash character (\) to remove the special meaning from a single character.
B. Variable dereferencing is the process of accessing a variable's value, which is done using a dollar sign ($), as in $VAR.
D. Output formatting is controlled by specific commands like printf or options to commands like echo, not by backticks. ---

References

1. GNU Bash Reference Manual, Section 3.5.4 Command Substitution: "Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command... When the old-style backquote form of substitution is used, backslash retains its literal meaning except when followed by ‘$’, ‘’, or ‘\’."

2. MIT, "The Missing Semester of Your CS Education", Lecture 1: The Shell: The course materials explain shell features, including command substitution. The notes state, "To use the output of a command as an argument to another command... you can use $(CMD)... An older syntax CMD is also supported." This confirms the use of backticks for this purpose.

3. Arista EOS 4.28.1F System Configuration Guide, Section: CLI Scripting: This guide details scripting on Arista devices. While it may not explicitly define backticks, the examples provided rely on standard Bash shell behavior, where command substitution is a fundamental feature for capturing command output within scripts running on the EOS Linux environment. For instance, capturing the output of a show` command into a variable uses this mechanism.

Scroll to Top