意外令牌完成附近的语法错误

时间:2017-04-19 12:07:26

标签: linux bash fedora

我一直收到上述错误,我无法对其进行编码。有人可以帮助检查错误,让我知道所以我可以运行它。这是使用替换算法。如果可以解决这个问题将非常感激。谢谢。

#!/bin/bash
#
cnt=0 #page fault
k=0   #pointer
pg=(0 0 0 0) #frame_number

IFS=";"","

filecontent=`cat < Input.csv`

array=($filecontent)

echo -e "Page Fault  \tpage 0 \t page 1\t page 2\tpage 3 "

for ((a=0; a<${#array[@]}; ++a))

do

    frame[$a]="-"
    usebit[$a]= 0


for pg in "${array[$a]}";

do

    flag=false

for ((a=0; a<${#array[@]}; ++a));

do
    if [${frame[$b]} = $pg];

then

    usebit[$b]=1
    flag=true
    break

  fi

done

let check=0

if [ $flag=false];

then
    while ($check -le $array];

    if [${usebit[$k]}=1;

    then
        usebit[$k]=0
        let "k++"

    else

        frame[$k]=$pg
        usebit[$k]=1

        echo "Page Fault = replace frame $k"

        let "cnt++"
        let "k++"

    if [$k = $array];

    then

        k=0
    fi

        break;
    fi

        if [$k = $array];

        then

            k=0

    fi


        let "check++"

   done

   echo -e " $cnt \t\t ${pg[0]}\t ${pg[1]} \t ${pg[2]} \t ${pg[3]} "
   done

  echo "The number of page fault for page frame of 4 in clock policy
  algorithm is $cnt"

1 个答案:

答案 0 :(得分:2)

http://www.shellcheck.net/在帮助编写shell脚本方面做得很好。您的代码中的错误如下所示:

Line 32:
if [${frame[$b]} = $pg];
^-- SC1009: The mentioned parser error was in this if expression.
   ^-- SC1035: You need a space after the [ and before the ].
   ^-- SC1073: Couldn't parse this test expression.
                       ^-- SC1020: You need a space before the ].
                       ^-- SC1072: Missing space before ]. Fix any mentioned problems and try again.

Line 46:
if [ $flag=false];
^-- SC1009: The mentioned parser error was in this if expression.
   ^-- SC1073: Couldn't parse this test expression.
                 ^-- SC1020: You need a space before the ].
                 ^-- SC1072: Missing space before ]. Fix any mentioned problems and try again.

......等等......