CLI

Term side of the Card.
Topic: Basics
Unit title: CLI
Categories: Software
Explanation side of the Card

Explanation: The interface that allows users to interact with a computer or application by typing text commands. Common in system administration and programming tasks.

Example

Wrongbash
rm -rf $BUILD_DIR/
Rightbash
rm -rf -- "${BUILD_DIR:?}/"

Quotes stop word splitting, and :? aborts the command when the variable is empty instead of deleting from the root.

Common mistakes

  • An empty variable turns rm -rf $DIR/ into rm -rf /.
  • A path with spaces is split into two arguments because it was not quoted.

Key points

  • Shell variables in commands are quoted, as in "$DIR", so spaces and empty values do not break them.
  • Destructive commands like rm -rf guard against empty paths, for example with ${DIR:?}.
  • Scripts exit with a non-zero code on failure, for example with set -e.

Interview questions

Why use a CLI instead of a GUI?

Commands can be repeated, combined with pipes, saved in scripts and run on servers without a screen.

What is the difference between a CLI and a terminal?

A CLI is any text command interface, including one a program provides. The terminal is the app where you type those commands.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy