nerdexam
Linux_Foundation

LFCS · Question #839

What does the following command do? cat '$TEST'

The correct answer is B. Displays the contents of the file named $TEST if it exists. The single quotes around $TEST prevent the shell from expanding the TEST environment variable, causing cat to attempt to display the contents of a file literally named "$TEST".

Submitted by skyler.x· Apr 18, 2026Essential Commands

Question

What does the following command do? cat '$TEST'

Options

  • ADisplays a bash syntax error message.
  • BDisplays the contents of the file named $TEST if it exists.
  • CWaits for the user to enter text and then echos the text back.
  • DDisplays the contents of the file named inside the back quotes.
  • EDisplays the contents of the file named by the environment variable TEST.

How the community answered

(38 responses)
  • B
    92% (35)
  • C
    5% (2)
  • E
    3% (1)

Why each option

The single quotes around `$TEST` prevent the shell from expanding the `TEST` environment variable, causing `cat` to attempt to display the contents of a file literally named "$TEST".

ADisplays a bash syntax error message.

This command is syntactically valid in Bash; it merely attempts to open a file with a literal name.

BDisplays the contents of the file named $TEST if it exists.Correct

Single quotes (`' '`) prevent all shell expansions, including variable expansion. Therefore, `cat '$TEST'` will interpret `$TEST` as a literal filename string and attempt to display the contents of a file literally named "$TEST" in the current directory if it exists.

CWaits for the user to enter text and then echos the text back.

`cat` without any arguments would wait for user input, but providing a filename, even a literal one, directs `cat` to that file.

DDisplays the contents of the file named inside the back quotes.

Backticks (`` ` ``) are used for command substitution, not single quotes; single quotes explicitly prevent such substitutions.

EDisplays the contents of the file named by the environment variable TEST.

The single quotes explicitly prevent the expansion of the `TEST` environment variable; if expansion were desired, the quotes would be omitted (e.g., `cat $TEST`).

Concept tested: Shell quoting (single quotes)

Source: https://www.gnu.org/software/bash/manual/bash.html#Single-Quotes

Topics

#Shell Quoting#Variable Expansion#cat command#Bash Fundamentals

Community Discussion

No community discussion yet for this question.

Full LFCS Practice