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.

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

The following shell script works but removes colored formatting generated by rspec:

echo "$OUTPUT"

How to preserve the colors?

share|improve this question
What is much more likely is rspec is simply not doing color formatting when not outputting directly to terminal. You need to find an option like --color=always to force color. The shell isn't stripping the color sequences - it doesn't even know how to do so. Why are you trying to save colored output in a variable anyways? Just output it directly. – jw013 Oct 31 '12 at 14:03
up vote 4 down vote accepted

It's common for programs with colorized output to disable it if they're not being run directly in a TTY, since you might be piping the output to a log file or to another process that expects plain text. Typically the programs offer a switch to manually force colors enabled, and rspec has one (--color), but for some reason it ignores it if you're not running in a TTY, which is really unusual behavior.

I think your only options are to edit rspec to take out that check (see def color in rspec-core-2.11.1/lib/rspec/core/configuration.rb), or run it within a program that will trick it into thinking it has a TTY, like expect

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.