0

所以我最近询问了意外的令牌 fi并修复了这些错误。现在我得到了不同的错误。有人可以通读我的脚本并指出或修复您看到的所有错误 - 我是 bash 新手,但没有收到一半的错误。例如:

$ composerrun.sh
./composerrun.sh: line 2: checkForComposerJson: command not found
./composerrun.sh: line 27: syntax error near unexpected token `)'
./composerrun.sh: line 27: `           [Nn]*) '

当我运行时:

#!/bin/bash


# We need to see if the AisisCore/ Directory exists.
# If it doesn't we will try and create it for you.
# Then to be safe - we check if it exists.
function checkForAisisCore {
    if [[-d "AisisCore/"]]
    then 
        return 0;
    else
       read -p "Would you like us to create the directory?" yn,
       case $yn in
           [[Yy]]*) 
               mkdir "AisisCore/";
               if [[-d "AisisCore/"]]
               then
                   return 0;
               else
                   echo "We could not create the directory as you requested";
                   return 1;
               end
               ;;
           [[Nn]]*) 
               return 1;
               ;;
           *) 
               echo "Please put in either yes or no";
       esac
   fi
}

# We check for the aisis-core inside of vender inside of adam.balan.
# If it exists return true.
# If Not, then alert the user and return false.
function checkForVendor(){
  if [[-d "vender/adam.balan/aisis-core/"]]
  then
      return 0;
  else
      echo "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
}

# We need to know if composer.json exists.
# If it does we return true.
# If not - we alert the user.
function checkForComposerJson(){
    if [[-f "composer.json"]]
    then
        return 0;
    else
        echo "You need composer.json with appropriate information about AisisCore";
        return 1;
    fi
}

# ================================ [ Core ] ================================

# Core program.
#
# Check if the composer.json and AisisCore/ exist.
# Run composer install.
# Check for vendor folder.
# If all is good - echo Found Vendor and exit. (For now).
if checkForComposerJson && checkForAisisCore
then
    composer install
    if checkForVendor
    then
        echo "Found vendor"; exit;
    fi
fi

我确信有数百个错误和问题,但我看不到它们,因为我不知道 bash。我认为我在正确的轨道上。我怎么能用另一双眼睛看这个剧本,就像“你在做什么……”



4

1 回答 1

3

在使用它们之前声明你的函数。用双分号 ( ;;) 分隔 case 子句。Prefer [[and ]]to [and ](see this SO discussion ),因为它们可以减少意外。

于 2013-09-20T19:38:50.253 回答