使用bash脚本时出现语法错误

时间:2013-04-28 22:25:38

标签: bash syntax

我一直试图解决这个错误2天,但我无法确定错误的确切位置。你能帮我解决这个小小的错误吗?

#!/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,它不允许脚本显示加速因子。

有什么想法吗?提前谢谢。

2 个答案:

答案 0 :(得分:1)

您从未设置seq_time,因此bc尝试评估的表达式为“236.771555 /”,这会产生语法错误。

答案 1 :(得分:0)

试试这个:

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