在bash脚本中找不到命令

时间:2018-12-02 20:27:41

标签: bash

我正在尝试使用此脚本计算一个简单的平均值

 for i in 1 2 3 4;
  do
    acum=0
    for n_proc in 1 2 3 4;
        do
          #obtenemos el comienzo
          start="$(date +'%s%3N')"
          mpirun -np $n_proc ./solver_async
          #obtenemos el final
          end="$(date +'%s%3N')"
          #obtenemos la duracion de la ejecucion
          duration=$(($end-$start))
          acum=$(( $acum + $duration ))

          result="$n_proc  $duration"
          #enviamos los datos al fichero result.dat
        done
        avg=$(( $acum / 4 ))
        echo $avg >> result5.dat
  done

但是它不起作用,我有一个语法错误

/opt/gridengine/default/spool/compute-0-8/job_scripts/459539: line 21: syntax error near unexpected token `('
/opt/gridengine/default/spool/compute-0-8/job_scripts/459539: line 21: `          acum=(($acum+$duration));'
/opt/gridengine/default/spool/compute-0-8/job_scripts/459539: line 25: syntax error near unexpected token `done'
/opt/gridengine/default/spool/compute-0-8/job_scripts/459539: line 25: `        done'

1 个答案:

答案 0 :(得分:2)

您应该替换行

 acum=$acum + $duration;

使用

 acum=$(( $acum + $duration ))

和行

avg=$acum/4

使用

avg=$(( $acum / 4 ))