Bash Scripting - 意外令牌fi

时间:2013-09-20 19:08:50

标签: bash shell

所以我正在尝试写一个bash脚本,声明:

如果文件存在且目录b存在,请运行composer install,检查vendor文件夹。如果我们找到它 - 回声并退出。

但它一直在说:

./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,如果它不存在我在哪里制作目录 - 我在单词之后做的检查 - 值得吗?

1 个答案:

答案 0 :(得分:5)

你忘了then。它应该是:

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

        echo "Found vendor"; exit;
    fi
fi