Badass Devil
Badass Devil

Reputation: 45

syntax error near unexpected token done

i keep getting the above error and i can't code it. can someone help check the error please and let me know so i can run it. This is using replacement algorithm. It will be much appreciated if this can be solved. Thank you.

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

Upvotes: 1

Views: 1961

Answers (1)

Jakuje
Jakuje

Reputation: 25926

http://www.shellcheck.net/ does a good way in helping to write you shell scripts. The error from your code look like this:

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.

... and so on ...

Upvotes: 3

Related Questions