简体   繁体   English

具有IF语句的Bash脚本,执行“ gem”并检查结果

[英]Bash Script with IF statement that executes “gem” and checks result

I am trying to write a bash script that checks if a gem is installed. 我正在尝试编写一个bash脚本来检查是否安装了gem。 If the gem is installed I will do option A. If not, I will do option B. 如果安装了gem,则将执行选项A。否则,将执行选项B。

To see if the gem is installed I use: 要查看是否已安装gem,请使用:

gem list -i "^gemname$"

This prints "true" or "false" to the screen. 这会在屏幕上显示“ true”或“ false”。 I think it outputs the text "true" and "false" but I am not sure if itself has a return value. 我认为它输出文本“ true”和“ false”,但是我不确定自身是否具有返回值。

The gem i am searching for is "xcpretty" and my script is: 我要搜索的宝石是“ xcpretty”,我的脚本是:

if [[$(gem list -i "^xcpretty$") == true]]; then
    echo "Found XCPRETTY do other things"
else
    echo "Cant find XCPRetty do things"
fi

This fails with the error: .xxxxx: line 1: [[false: command not found 失败并显示以下错误:.xxxxx:第1行:[[false:未找到命令

Because the gem is not installed on my system, it returned "false". 由于未在我的系统上安装gem,它返回了“ false”。 But how do I compare what it returned with "false"? 但是,我该如何比较它返回的“ false”呢?

Thanks! 谢谢!

[[和之前]]之后添加空格。

[[ $(gem list -i "^xcpretty$") == true ]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM