LinuxCommandLibrary

false

Return an unsuccessful (false) exit status

TLDR

Return a non-zero exit code

$ false
copy

SYNOPSIS

false [arguments...]

PARAMETERS

[arguments...]
    Any supplied command line arguments are ignored and have no effect on the command's behavior. This is explicitly stated in some false manual pages.

--help
    Display a help message and exit. This option is typically available when false is an external utility (e.g., /bin/false), not a shell built-in.

--version
    Output version information and exit. This option is typically available when false is an external utility, not a shell built-in.

DESCRIPTION

The false command is a fundamental Unix-like utility designed to perform a single, straightforward action: it always exits with a non-zero status code. By convention in shell scripting and Unix philosophy, a non-zero exit status indicates a 'failure' or 'unsuccessful' operation, while a zero status signifies 'success'.

It serves as the logical opposite of the true command, which always exits with a zero (success) status. Despite its apparent simplicity, false is extremely useful in shell scripting for controlling program flow, particularly in conditional statements (like if and while loops) or logical operations (&&, ||). It can be used to intentionally trigger a failure path, prevent a loop from running, or as a placeholder where an unsuccessful command is required.

Most commonly, false is implemented as a shell built-in (e.g., in bash or sh), meaning it is executed directly by the shell without launching an external program. This makes it highly efficient, incurring minimal overhead. The command typically accepts no meaningful arguments; any supplied arguments are usually ignored.

CAVEATS

The behavior of false can vary slightly depending on whether it is executed as a standalone external utility (e.g., /bin/false) or as a shell built-in. Shell built-in versions are generally more efficient as they avoid the overhead of spawning a new process. External versions might support standard GNU options like --help and --version, which built-ins often do not.

EXIT STATUS

The primary function of false is to exit with a non-zero status code, conventionally indicating a 'failure' or 'unsuccessful' operation. In most Unix-like systems, this exit status is 1, though any non-zero value signifies failure.

COMMON USE CASES IN SHELL SCRIPTING

false is invaluable in shell scripting for controlling program flow:

Conditional Logic:

if false;
then
echo "This message will not be printed.";
fi

Loop Control:
while false;
do
echo "This loop will never execute.";
done

Logical Operations:
# Forces the logical AND chain to fail
command_that_succeeds && false && command_that_wont_run

# Forces the logical OR chain to execute the second command
false || command_that_will_run

HISTORY

The false command, like its counterpart true, is a fundamental and ancient utility in Unix-like operating systems. It dates back to the very early days of Unix, providing a simple, reliable way to signal a failure status. Its extreme simplicity has meant little to no 'development' in terms of features over the decades. Its most significant evolution has been its common implementation as a shell built-in in popular shells like sh and bash, enhancing its performance for scripting by avoiding the overhead of external process execution.

SEE ALSO

true(1), test(1), sh(1), bash(1), exit (shell built-in)

Copied to clipboard