Bill L
Bill L

Reputation: 2826

Silence gem list console output

I'm writing a bash script to run a ruby command and it requires a few gems. I'm checking if the gem is installed and installing it like so:

if ! gem list rest-client -iq
then
    echo "Missing rest-client gem, installing now..."
    gem install rest-client
fi

This works great, except for the fact that is outputs true or false. Looking at the help pages, I think adding the q option is suposed to silence this output, however I may be wrong.

How do I go about suppressing the true or false output and just act on it?

Upvotes: 1

Views: 276

Answers (2)

shime
shime

Reputation: 9008

Use the --silent flag.

gem list -i rest-client --silent

Upvotes: 0

fedorqui
fedorqui

Reputation: 289725

As indicated in the comments, just redirect the stdout to /dev/null so that it does not show:

if ! gem list rest-client -iq >/dev/null
#                             ^^^^^^^^^^
then
    echo "Missing rest-client gem, installing now..."
    gem install rest-client
fi

Upvotes: 1

Related Questions