使用bash脚本的语法错误

问题描述:

我一直试图解决这个错误2天,但我无法弄清楚错误发生在哪里。你能帮我解决这个小小的错误吗?使用bash脚本的语法错误

#!/bin/bash 

ntests=10 
param_vertexes=10 
param_pop=10 

echo -e "\nExecution of parallel with 8 threads for $ntests times." 
par8_time=0 
for i in $(seq $ntests); do 
    output=$(./parallel -t 8 $param_vertexes $param_pop) 
    echo $output 
    par8_time=$par8_time+$(echo $output | cut -d' ' -f6) 
done 
par8_time=$(echo $par8_time | bc) 
echo "Total Iteration/Time: $par8_time" 
echo "Speedup of 8 threads: $(echo -e "scale=10\n"$par8_time/$seq_time | bc)" 

我不断收到同样的错误

Execution of parallel with 8 threads for 10 times. 
Sequential iterations/time = 23.642725 
Sequential iterations/time = 23.860021 
Sequential iterations/time = 23.703970 
Sequential iterations/time = 23.513577 
Sequential iterations/time = 23.728710 
Sequential iterations/time = 23.790608 
Sequential iterations/time = 23.590524 
Sequential iterations/time = 23.612470 
Sequential iterations/time = 23.653072 
Sequential iterations/time = 23.675878 
Total Iteration/Time: 236.771555 
    (standard_in) 3: syntax error 
    Speedup of 8 threads: 

正如你所看到的,只有问题与我的脚本是syntax error尚未允许脚本来显示加速比。

任何想法?提前致谢。

试试这个:

a=$(echo -e "scale=10;$par8_time/$seq_time" | bc) 
echo "Speedup of 8 threads: $a" 
+0

我试过,但它不能解决问题 – 2013-04-28 23:11:02

+0

它给了我同样的错误“语法错误” – 2013-04-28 23:13:31

你从未seq_time,使表达bc试图评估为 “236.771555 /”,这给出了一个语法错误。

+0

+1好的捕获没有看到那个。 – 2013-04-29 00:43:37

+0

非常感谢...我会尽力根据您的评论来解决它 – 2013-04-29 04:08:01