Output and evaluation

This topic gathers the small, sharp commands that scripts are built from: the ones that print something, that read or set the environment, that evaluate an expression or a condition, and that simply succeed or fail.

The commands #

Producing text

CommandPurpose
echoPrint its arguments as a line of text.
printfPrint text from a format string, with precise control over layout.
yesPrint a line over and over, without stopping.
seqPrint a sequence of numbers.
teeCopy standard input to standard output and to each named file.

The environment

CommandPurpose
envRun a command with a modified environment — or print the current one.
printenvPrint environment variables.

Numbers

CommandPurpose
numfmtConvert numbers to and from human-readable forms (1.5G, 1000000).
factorPrint the prime factors of a number.

Evaluating

CommandPurpose
exprEvaluate an arithmetic, string, or comparison expression.
testEvaluate a condition — a file check or a comparison — as a true/false result.

Exit status

CommandPurpose
true and falseDo nothing, and succeed — or do nothing, and fail.

A note on exit status #

Several commands here exist to be used for their exit status rather than their output. Every command, when it finishes, leaves behind a number: 0 means success, anything else means a kind of failure. A shell's if, &&, and || all act on that number.

test is the clearest case — it prints nothing and exists only to set an exit status from a condition. true and false are the most minimal: fixed success and fixed failure. Where this topic's pages give an exit-status table, that number is often the whole point of the command.

Where to start #

For everyday printing, echo; for anything that needs columns, padding, or precise formatting, printf.

Edit this page