在bash中运行条件脚本[重复]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在bash中运行条件脚本[重复]相关的知识,希望对你有一定的参考价值。

这个问题在这里已有答案:

这是我用来检查当前git分支的代码,

branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')

如果分支是master,我想有条件地运行以下代码

cd build && aws s3 cp . s3://www.examle.com/ --recursive

我怎么在bash中这样做?

答案
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [ "$branch" = master ]; then
   cd build && aws s3 cp . s3://www.examle.com/ --recursive
fi
另一答案

尝试如下

[[ "$branch" == master ]] && cd build && aws s3 cp . s3://www.examle.com/ --recursive

以上是关于在bash中运行条件脚本[重复]的主要内容,如果未能解决你的问题,请参考以下文章