Bashスクリプトを実行できません(予期しない要素 '(')

Bashスクリプトを実行できません(予期しない要素 '(')

Node、Npm、Bower、Susyがインストールされていることを確認するスクリプトを作成しましたが、実行すると解決できないというエラーが発生します。

スクリプトは次のとおりです。

    isInstalled(){
  command -v $1 >/dev/null 2>&1 || command -v $2 >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not installed.  Aborting."; return false;}  
}

installNode() {
  if [[ !isInstalled('node', 'nodejs') ]]; then
    echo "Node is not installed. Installing..."
    curl https://www.npmjs.org/install.sh | sh
  fi
}

installBower()
{

   if [[ !isInstalled('npm') ]]; then
     echo "Npm is not installed. Installing..."
     curl -L https://npmjs.org/install.sh | sh
   else
     echo "Npm is installed. Checcking Bower..."
   if [[ !isInstalled('bower') ]]; then
     echo "Bower is not installed. Installing..."
     npm install -g bower
   fi

}

installSusy()
{

  if [[ !isInstalled('npm') ]]; then
     echo "Npm is not installed. Installing..."
     curl -L https://npmjs.org/install.sh | sh
   else
     echo "Npm is installed. Checcking Bower..."
   if [[ !isInstalled('bower') ]]; then
     echo "Susy is not installed. Installing..."
     npm install susy
   fi


}

エラーメッセージは次のとおりです。

begin.sh: 6: begin.sh: Syntax error: "(" unexpected (expecting "then")

ベストアンサー1

の関数は、bash他の言語の関数とは異なり、コマンドのように呼び出されます。代わりに、isInstalled('node', 'nodejs')以下を実行してください。

isInstalled 'node' 'nodejs'

条件ifは次のとおりです。

if ! isInstalled 'node' 'nodejs';
then
    ...

おすすめ記事