LinuxCommandLibrary

true

Return a zero exit status (always true)

TLDR

Return a successful exit code

$ true
copy

SYNOPSIS

true
No options or arguments are accepted.

DESCRIPTION

The true command is a fundamental utility in Unix-like operating systems, including Linux, whose sole purpose is to exit with a successful status code of zero. Despite its apparent simplicity and lack of functional output, it plays a crucial role in shell scripting and conditional logic. Programmers and scriptwriters often leverage true in contexts where a command's success or failure is the primary concern, rather than its side effects or output. For instance, it is commonly used to create infinite loops (e.g., `while true; do ...; done`), or as a placeholder in conditional statements where a no-operation success is required. Its behavior is precisely the opposite of the false command, which always exits with a non-zero (unsuccessful) status code. Being part of the GNU core utilities, true is a reliable and universally available command, making it an indispensable tool for robust shell programming. Its minimalistic design underscores the Unix philosophy of providing small, specialized tools that can be combined to achieve complex tasks.

CAVEATS

The true command's simplicity means it has very few caveats. Its primary limitation is that it performs no action other than returning an exit status. Users should be aware that it accepts no arguments or options; providing any will usually result in an error or be ignored depending on the specific implementation, although standard implementations like GNU Coreutils' true do not accept arguments. Attempting to use it for tasks other than providing a success exit status will be ineffective.

EXIT STATUS

The true command always exits with a status code of 0 (zero). In Unix-like systems, an exit status of zero conventionally indicates success, while a non-zero status indicates failure. This consistent success code is the command's defining characteristic and its sole functional output.

HISTORY

The true command, along with its counterpart false, are among the most basic and oldest utilities in the Unix ecosystem. Their origins can be traced back to the early days of Unix and its shell scripting environment. Their existence is a testament to the fundamental need for commands that simply return a specific exit status without performing any other operation, essential for controlling program flow in scripts. As part of the GNU Core Utilities, true has been a standard component of Linux distributions since their inception, ensuring its universal availability and consistent behavior across various systems. Its simple, singular purpose has remained unchanged over decades, reflecting its enduring utility in the design of robust shell scripts.

SEE ALSO

false(1), :(1), test(1)

Copied to clipboard