Standard Command That Always Exits with a Failure

command lineexitexit-statusshellshell-script

I want to test my script with a command that fails. I could use an existing command with bad arguments. I could also write a simple script that immediately exits with a failure. Both of these are easy to do and work for me, but if there is a standard command for this purpose, I'd like to use that instead.

Best Answer

You can use false (/bin/false, /usr/bin/false, or shell builtin):

$ false || echo It failed.
It failed.
$

You can also use exit 1 from a subshell:

$ (exit 1) || echo Gosh, it failed too.
Gosh, it failed too.
$
Related Question