我想要的是
if((TRAVIS_BRANCH != "master") || (TRAVIS_BRANCH == "master" && TRAVIS_PULL_REQUEST == true)
我如何在bash中执行此操作?我认为这是最接近的,但它仍然不起作用
if [ "$TRAVIS_BRANCH" != "master" ] || ["$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "true"]
答案 0 :(得分:1)
在命令名称周围添加空格([
是命令名称),不要在单个&&
命令中尝试使用||
或[
。
if [ "$TRAVIS_BRANCH" != "master" ] || { [ "$TRAVIS_BRANCH" = "master" ] && [ "$TRAVIS_PULL_REQUEST" = "true"]; }
但是,您可以在&&
内使用||
或[[ ]]
,并且也不需要在那里引用:
if [[ $TRAVIS_BRANCH != master ]] || [[ $TRAVIS_BRANCH = master && $TRAVIS_PULL_REQUEST = true ]]
答案 1 :(得分:1)
[
和]
字符被空格包围-a
&&
,而不是[
[[
而不是[
结果:
is_master_pull_request() {
[[ "$TRAVIS_BRANCH" = "master" ]] && [[ "$TRAVIS_PULL_REQUEST" = "true" ]]
}
if [[ "$TRAVIS_BRANCH" != "master" ]] || is_master_pull_request
答案 2 :(得分:0)
尝试:
if [ "$TRAVIS_BRANCH" != "master" ] || [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "true" ]]; then