Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 25 down vote accepted

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.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.