jeudi 22 janvier 2015

Bash - syntax error near unexpected token `fi'


#!/usr/bin/env bash

if [[ $# -eq '0' ]]
then
var=command

if [[ ${var} -eq '0' ]]
then
do something
else
do something else
fi
fi

if [[ $# -eq '1' ]]
usage;
fi

if [[ $# -eq '2' ]]
if [[ "$1" != "-r" ]]
then
usage;
fi
if [[ "$2" =~ some_pattern ]]
then
do something
else
echo "Pattern is in an improper format. Please enter it as: correct_pattern, and try again"
exit 1
fi
usage="Usage: meta_script.sh -r correct_pattern
-r for reset is used to manually pass a parameter instead of using the default"
exit 1
fi


When I run this script, this is the error I get:



./meta_script.sh: line 31: syntax error near unexpected token `fi'
./meta_script.sh: line 31: `fi'


In the first if statement where I'm checking if the number of parameters are equal to 1, I had put a then, but I got the same error as above, except with then instead of fi. It's almost as if no matter what I put and where, I get these errors and when I remove them to try and fix it, I get another bunch of similar errors. Please help me correct this script. Thanks!


Aucun commentaire:

Enregistrer un commentaire