My bash script is the following
#!/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
However, I get the error message (standard_in) 1: syntax error.
Do you have any idea to address this issue? Thank you in advance!
The equivalent R code is the following
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)
}
}
bcerror, not a bash error -- different languages with different syntax. If you want to know what operations bash is tellingbcto do, usingset -xto enable tracing would be a good place to start, and would make the bug very clear (you'd see bash telling bc to calculate with{0.01as a number, with the{as part of its value, f/e).