【问题标题】:Bash Scripting - unexpected token fiBash 脚本 - 意外的令牌 fi
【发布时间】:2013-09-26 06:38:27
【问题描述】:

所以我正在尝试编写一个 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,如果目录不存在,我会在其中创建目录 - 我在单词之后进行的检查 - 是否值得?

【问题讨论】:

标签: bash shell


【解决方案1】:

您忘记了then。应该是:

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

        echo "Found vendor"; exit;
    fi
fi

【讨论】:

  • @LogicLooking 对于if 的其余部分也是如此,您还少了几个 :)
猜你喜欢
  • 1970-01-01
  • 2020-10-09
  • 2016-08-11
  • 1970-01-01
  • 2015-07-14
  • 1970-01-01
  • 1970-01-01
  • 2016-08-06
  • 1970-01-01
相关资源
最近更新 更多