Linux false command
"Do nothing, and fail."
On Unix-like operating systems, the false command's sole purpose is to return an exit status indicating failure. It is useful when you want part of a command pipeline or conditional expression to always fail.
Syntax
false [anything ...]
When provided no arguments, false fails.
When provided any number of arguments, false fails.
Exit status
The false command always returns 1, representing "false" or "failure".
Examples
false
Outputs nothing, with an exit status of 1.
false true maybe-true maybe-false "possibly partly true" 6 file.jpg -t -x
Outputs nothing, with an exit status of 1.
You can verify the exit status by checking the value of the special shell variable ?, which contains the exit status of the previous command. For instance, in the next command, we use a semicolon (;) to execute two commands in one line. The second command is echo, which prints the value of ?, which like all shell variables may be referenced by prefixing the variable name with $.
false; echo "The previous command's exit status is $?."
The previous command's exit status is 1.
Two examples of using false in an "if" statement:
if false; then echo "False"; else echo "True"; fi
False
In the next example, the ! reserved character returns the negation of the pipeline it precedes. In other words, if ! false is equivalent to if true. (See: Pipelines in bash for more information.)
if ! false; then echo "True, because \"not false\" is true."; else echo "False"; fi
True, because "not false" is true.
An example of using false in a "while" statement:
while false; do echo "This line will never run."; done echo "(But this one will.)"
(But this one will.)
Related commands
true — Return an exit status of success.
yes — Output "y", or any other text, forever.
test — Test for file attributes, or compare values.