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 have a makefile where I'm stopping a service before removing a file. When it couldn't stop the service, it would break on error. This is clearly unwanted so I thought I'd add || true but missed a |. Making it:

stop service foo | true
rm /etc/init/foo.conf

I'm confused as to why this is working and what is happening. Does this mean that true is an application and not merely a keyword? Are they the same? Is there a good reason to use | true?

share|improve this question
up vote 12 down vote accepted

true and false are coreutils (also typically shell built-ins) that just return 0 and non-0, for situations where you happen to need that behavior. From the man pages:

true - do nothing, successfully
false - do nothing, unsuccessfully

So you're piping the output from stop service foo into true, which ignores it and returns 0. Technically it works, but you should probably use || true so it's obvious what your intention was; there's really no reason to pipe output into a program that's not using it

share|improve this answer
Makes perfect sense. :) I don't know why but reading "do nothing, unsuccessfully." makes me laugh. – Kit Sunde Apr 24 '11 at 20:23
Another reason to avoid | true is that if the command produced enough output to fill up the pipe buffer, it would block waiting for true to read it. – cjm Apr 24 '11 at 20:53
@cjm or die due to SIGPIPE – Andy Apr 25 '11 at 4:43
@Kit: Note that foo || true and foo | true won't do the same thing: foo || true will show the output from foo, whereas foo | true will discard everything foo writes to its standard output (and foo is likely to die with SIGPIPE or block, as already indicated). – Gilles Apr 25 '11 at 22:06

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.