Linux 意外标记附近的语法错误';{';

Linux 意外标记附近的语法错误';{';,linux,bash,shell,command-line,Linux,Bash,Shell,Command Line,我有一个脚本,它检查一些基本MIPS指令的语法。但是,当我运行它时,我在控制台中得到以下输出: bash valsplit.sh input.txt correct.txt incorrect.txt functions.sh: line 31: syntax error near unexpected token `}' functions.sh: line 31: `}' valsplit.sh: line 49: syntax error near unexpected token `do

我有一个脚本,它检查一些基本MIPS指令的语法。但是,当我运行它时,我在控制台中得到以下输出:

bash valsplit.sh input.txt correct.txt incorrect.txt
functions.sh: line 31: syntax error near unexpected token `}'
functions.sh: line 31: `}'
valsplit.sh: line 49: syntax error near unexpected token `done'
valsplit.sh: line 49: `  done <$input'
知道为什么会抛出错误消息吗?

报告:

else if [ $line == addi* ]; then 
^–– SC1075 Use 'elif' instead of 'else if'.
                   ^–– SC2081 [ .. ] can't match globs. Use [[ .. ]] or grep.

还有许多其他错误和警告。请在其网站上运行脚本以查看完整列表

#!/bin/bash

#Checks instruction syntax is correct
#Pass the entire line as an argument
check_correct_instruction_syntax() {
  for word in "${$1[0]}"; do
    if [[ $word != add ]] && [[ $word != sub ]] && [[ $word != addi ]] && [[ $word != lw ]] && [[ $word != sw ]]; then
      $error_file="$error_file \n Incorrect instruction. Use add, sub, addi, lw or sw." 
      error_count=`expr $error_count + 1`
    fi 
  done        
}

#Checks number of paramters is correct
#Pass the entire line as an argument
check_correct_num_of_params() {

  a=( $1 )
  word=${1[0]}
  if [[ $word == add ]] || [[ $word == sub ]] || [[ $word == addi ]]; then 
    if [[ ${#$1[@]} != 4 ]]; then  
      $error_file="$error_file \n Incorrect number of paramters for instruction ${a[0]}. It should have 3."
      error_count=`expr $error_count + 1`
    fi
  else if [[ $word == lw ]] || [[ $word == sw ]]; then 
    if [[ ${#$1[@]} != 3 ]]; then 
      $error_file="$error_file \n Incorrect number of paramters for instruction ${a[0]}. It should have 2."
      error_count=`expr $error_count + 1`
    fi
  fi  
}

#Checks register syntax is correct
#Pass the register to be checked as an argument
check_register_syntax() {

  register="$1"

  if [ "${register:0:1}" != "$" ]; then 
    $error_file="$error_file \n Incorrect register syntax. Registers should start with a $."
    error_count=`expr $error_count + 1`
  fi

  if [[ ! ${register:1:2} == "t" ]] && [[ ! ${register:1:2} == "s" ]]; then
    $error_file="$error_file \n Unrecognized register name $register. Use s or t."
    error_count=`expr $error_count + 1`
  fi

  if [ "${register:1:2}" = "t" ]; then
    if [ ! "${register:2:3}" -ge 0 -a "${register:2:3}" -le 9 ]; then
      $error_file="$error_file \n Incorrect register number. Temporary registers are numbered 0 to 9."
      error_count=`expr $error_count + 1`
    fi
  fi  


  if [ "${register:1:2}" = "s" ]; then 
    if [ ! "${register:2:3}" -ge 0 -a "${register:2:3}" -le 7 ]; then
      $error_file="$error_file \n Incorrect register number. Permanent registers are numbered 0 to 7."
      error_count=`expr $error_count + 1`
    fi 
  fi

}

#Check the immediates are within the correct range
#Pass the immediate as an argument 
check_immediate_range() {
  if [ ! $1 -ge -32768 -a $1 -le 32767 ]; then
    $error_file="$error_file \n Out of bounds immediate $1. Immediates range between -32768 and 32767."
    error_count=`expr $error_count + 1`
  fi
}

#Check the second param for sw or lw contains an immediate and a register
#Pass the entire line as a paramter
check_sw_or_lw_immediate_register_param() {
  if [[ $1 == sw* ]] || [[ $1 == lw* ]]; then
    a=( $1 )
    second_param="${a[2]}"
    check_immediate_range ${second_param:0:1}
    check_register_syntax ${second_param:2:5}
}
else if [ $line == addi* ]; then 
^–– SC1075 Use 'elif' instead of 'else if'.
                   ^–– SC2081 [ .. ] can't match globs. Use [[ .. ]] or grep.
if [[ $1 == sw* ]] || [[ $1 == lw* ]]; then
^–– SC1046 Couldn't find 'fi' for this 'if'.