HOME

TheInfoList



OR:

In
Unix-like A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating system An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
s, true and false are commands whose only function is to always return with a predetermined
exit status In computing, the exit status (also exit code or exit value) of a terminated process is an integer number that is made available to its parent process (or caller). In DOS, this may be referred to as an errorlevel. When computer programs ar ...
. Programmers and scripts often use the exit status of a command to assess success (exit status zero) or failure (non-zero) of the command. The true and false commands represent the
logical value In logic and mathematics, a truth value, sometimes called a logical value, is a value indicating the relation of a proposition to truth, which in classical logic has only two possible values ('' true'' or '' false''). Truth values are used in c ...
s of command success, because ''true'' returns 0, and ''false'' returns 1.These are distinct from the
truth value In logic and mathematics, a truth value, sometimes called a logical value, is a value indicating the relation of a proposition to truth, which in classical logic has only two possible values ('' true'' or '' false''). Truth values are used in ...
s of
classical logic Classical logic (or standard logic) or Frege–Russell logic is the intensively studied and most widely used class of deductive logic. Classical logic has had much influence on analytic philosophy. Characteristics Each logical system in this c ...
and most general purpose programming languages: true (1 or T) and false (0 or ⊥).


Usage

The commands are usually employed in conditional statements and loops of
shell script A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipu ...
s. For example, the following shell script repeats the ''echo hello'' loop until interrupted: while true do echo hello done The commands can be used to ignore the success or failure of a sequence of other commands, as in the example: make … && false Setting a user's login shell to , in /etc/passwd, effectively denies them access to an interactive shell, but their account may still be valid for other services, such as
FTP The File Transfer Protocol (FTP) is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network. FTP is built on a client–server model architecture using separate control and dat ...
. (Although , if available, may be more fitting for this purpose, as it prints a notification before terminating the session.) The programs take no "actual" parameters; in the GNU version, the standard parameter --help displays a usage summary and --version displays the program version.


Null command

The ''true'' command is sometimes substituted with the very similar null command, written as a single colon (:). The null command is built into the shell, and may therefore be more efficient if ''true'' is an external program (''true'' is usually a shell built in function). We can rewrite the upper example using : instead of true: while : do echo hello done The null command may take parameters, which are ignored. It is also used as a
no-op In computer science, a NOP, no-op, or NOOP (pronounced "no op"; short for no operation) is a machine language instruction and its assembly language mnemonic, programming language statement, or computer protocol command that does nothing. Mac ...
dummy command for side-effects such as assigning default values to shell variables through the $ parameter expansion form. For example, from '' bashbug'', the bug-reporting script for Bash: : $ : $ : $


See also

*
List of Unix commands This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...
*
Two-valued logic In logic, the semantic principle (or law) of bivalence states that every declarative sentence expressing a proposition (of a theory under inspection) has exactly one truth value, either true or false. A logic satisfying this principle is calle ...
* IEFBR14


Notes


References


External links

* *


Manual pages


true(1)
Do nothing, successfully –
GNU GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
Coreutils The GNU Core Utilities or coreutils is a collection of GNU software that implements many standard, Unix-based shell commands. The utilities generally provide POSIX compliant interface when the environment variable is set, but otherwise offers ...
reference
false(1)
Do nothing, unsuccessfully –
GNU GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
Coreutils The GNU Core Utilities or coreutils is a collection of GNU software that implements many standard, Unix-based shell commands. The utilities generally provide POSIX compliant interface when the environment variable is set, but otherwise offers ...
reference
true(1)
Return true value –
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
manual page
false(1)
Return false value –
FreeBSD FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
manual page {{Core Utilities commands Standard Unix programs Unix SUS2008 utilities IBM i Qshell commands