Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 22 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
add comment

Your Answer

 
discard

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.