Test Command

noun

say it: “TEST kuh-MAND” /ˈtɛst kəˈmænd/

A command that checks whether something is true, such as whether a file exists, and answers yes or no with its exit code.

What is a test command in bash?

A test command checks one thing and answers with its exit code: 0 for yes, 1 for no. Bash's is [[ ]], with a space inside each bracket: it compares text with ==, numbers with -lt and its friends, and asks about files with -e. The older [ ] does much the same.

[[ 10 -lt 9 ]]; echo $?        # 1: no
[[ -e essay.txt ]]; echo $?    # 0: yes, it exists

In a sentence

  • “The test command -e essay.txt answers 0 because the file is there.”
  • “Forgetting the space after breaks the [[test command.”

Level: Apprentice · More Unix terms at this level

Updated