Linux 完成意外标记附近的语法错误
我不断得到上面的错误,我无法编码它。请有人帮我检查错误,让我知道,这样我就可以运行它了。这是使用替换算法。如果能解决这个问题,我们将不胜感激。多谢各位Linux 完成意外标记附近的语法错误,linux,bash,fedora,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 \
#!/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"
#/bin/bash
#
cnt=0#页面错误
k=0#指针
pg=(0)帧号
IFS=“;”,“
filecontent=`cat
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.
…等等…有几个语法错误。一个很好的起点是将代码粘贴到shellchecker中:并且代码通过了测试。您没有关闭所有的条件语句和循环。我计算了一个缺少的fi
和一个缺少的done
以及不匹配的参数if[${usebit[$k]}=1
应该是如果[${usebit[$k]}-eq 1]
只是一个例子-至少还有一个例子,在更改IFS时您应该小心,因为这是一个在许多命令中使用的特殊shell变量。请在缩进部分留出一些时间,以便您清楚地看到哪个if
属于哪个fi
,哪个do
属于哪个done
等等。到目前为止,这是非常不可理解的因此错误可能有点混淆。第23行:“${array[$a]}”中的for pg^--SC1009:提到的解析器错误在这个for循环中。这是什么意思?下一行告诉您需要什么-[…]
中的空格。