2

所以我正在尝试编写一个 bash 脚本,其中指出:

如果文件 a 存在,并且目录 b 存在,则运行 composer install,检查供应商文件夹。如果我们找到它 - 回显某些内容并退出。

但它一直在说:

./composerrun.sh: line 6: syntax error near unexpected token `fi'
./composerrun.sh: line 6: `    fi'

而且我太新了,无法理解这个结束的“大括号”是如何错误的:

#!/bin/bash
if checkForComposerJson && checkForAisisCore
    composer install
    if checkForVendor
        echo "Found vendor"; exit;
    fi
fi

function checkForAisisCore {
    if [-d "AisisCore/"]
    then 
        return 0;
    else
       echo "would you like us to create the directory?" yn,
       case $yn in
           Yes ) 
               mkdir "AisisCore/";
               if [-d "AisisCore/"]
                   return 0;;
               else
                   echo "We could not create the directory as you requested";
                   return 1;;
               end
           No ) return 1;;
           * ) echo "Please put in either yes or no";
       esac
   fi
}

function checkForVendor(){
  if [-d "vender/adam.balan/aisis-core/"]
      return 0;
  else
      "Something is wrong. We could not find the vendor/ folder. Please check that you are running this script inside of your theme or project folder.";
      return 1;
  fi
}

function checkForComposerJson(){
    if [-f "composer.json"]
        return 0;
    else
        echo "You need composer.json with appropriate information about AisisCore";
        return 1;
    fi
}

另外,我的 mkdir,如果目录不存在,我会在其中创建目录 - 我在单词之后进行的检查 - 是否值得?

4

1 回答 1

5

你忘了一个then. 它应该是:

if checkForComposerJson && checkForAisisCore
then  ## <-------------------
    composer install
    if checkForVendor
    then  ## <-------------------

        echo "Found vendor"; exit;
    fi
fi
于 2013-09-20T19:10:00.287 回答