2017-04-19 66 views
1

我不断收到上述错误,我无法对其进行编码。有人可以帮助检查错误,请让我知道,所以我可以运行它。这是使用替换算法。如果能解决这个问题,我们将非常感激。谢谢。意外令牌附近的语法错误完成

#!/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

有几个语法错误。一个好的起点是将你的代码粘贴到一个shellchecker中:http://www.shellcheck.net/并且你的代码通过了这个测试。 – odradek

+0

您并未关闭所有的条件语句和循环。如果[$ {usebit [$ k]} = 1'应该是'if [$ {usebit [$ k]} -eq 1]',那么我计算一个缺少'fi'和一个缺少'done' –

+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. 

...等等...

+0

Line 23: for pg in“$ {array [$ a]}”; ^ - SC1009:提到的解析器错误是在这个循环中。 这是什么意思? –

+0

下一行说明你需要什么 - “'[']里面的空格”。 – Jakuje

+0

@Jakuje不错的网站,解决我的问题。 +1 –

相关问题