Bash script Error: (standard_in) 1: syntax error

Bash script Error: (standard_in) 1: syntax error

我的bash脚本如下

#!/bin/bash
wc=(5000 10000 20000 50000);
for r2 in {0.01 0.1 0.4 0.7 0.95};
do
  for i in {0..3};
  do

    rr=$(echo "${r2} * 100" | bc)
    ww=$(echo "${wc[$i]} / ${rr}" | bc)
    echo $ww

  done
done

但是,我收到错误消息 (standard_in) 1: syntax error

您有解决此问题的想法吗?提前致谢!

等效的R代码如下

wc <- c(50,100,200,500)
for(k in c(0.01,0.1,0.4,0.7,0.95)){
   for(i in 1:4){
      
       ww <- floor(wc[i]/k)
       print(ww)
   }

}

大括号表达式中需要逗号:

for r2 in {0.01,0.1,0.4,0.7,0.95};

否则,您只是在迭代序列 {0.010.1、...、0.95}

无论如何都不需要大括号表达式:

for r2 in 0.01 0.1 0.4 0.7 0.95;