Silence gem 列出控制台输出
Silence gem list console output
我正在为 运行 一个 ruby 命令编写一个 bash 脚本,它需要几个 gem 。我正在检查是否安装了 gem 并像这样安装它:
if ! gem list rest-client -iq
then
echo "Missing rest-client gem, installing now..."
gem install rest-client
fi
这很好用,除了输出 true
或 false
。查看帮助页面,我认为添加 q
选项应该使此输出静音,但我可能错了。
如何抑制 true
或 false
输出并对其采取行动?
如评论中所述,只需将 stdout
重定向到 /dev/null
,这样它就不会显示:
if ! gem list rest-client -iq >/dev/null
# ^^^^^^^^^^
then
echo "Missing rest-client gem, installing now..."
gem install rest-client
fi
使用 --silent
标志。
gem list -i rest-client --silent
我正在为 运行 一个 ruby 命令编写一个 bash 脚本,它需要几个 gem 。我正在检查是否安装了 gem 并像这样安装它:
if ! gem list rest-client -iq
then
echo "Missing rest-client gem, installing now..."
gem install rest-client
fi
这很好用,除了输出 true
或 false
。查看帮助页面,我认为添加 q
选项应该使此输出静音,但我可能错了。
如何抑制 true
或 false
输出并对其采取行动?
如评论中所述,只需将 stdout
重定向到 /dev/null
,这样它就不会显示:
if ! gem list rest-client -iq >/dev/null
# ^^^^^^^^^^
then
echo "Missing rest-client gem, installing now..."
gem install rest-client
fi
使用 --silent
标志。
gem list -i rest-client --silent