(standard_in) 1: bash 脚本中的语法错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27134988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:45:23  来源:igfitidea点击:

(standard_in) 1: syntax error in bash script

bashsyntax-error

提问by Reluctant_Linux_User

I'm trying to generate some quasi random numbers to feed into a monte carlo simulation. I'm using bash. I seem to have hit a syntax error which I've narrowed down to being in this bit of code.

我正在尝试生成一些准随机数以输入蒙特卡罗模拟。我正在使用 bash。我似乎遇到了一个语法错误,我已将其范围缩小到这段代码中。

randno4=($RANDOM % 100001)
upper_limit4=$(echo "scale=10; 1*75.3689"|bc)
lower_limit4=$(echo "scale=10; 1*75.1689"|bc)
range4=$(echo "scale=10; $upper_limit4-$lower_limit4"|bc)
t_twall=`echo "scale=10; ${lower_limit4}+${range4}*${randno3}/100001" |bc`
echo "$t_twall"

Does anyone know why I the below output and not a value between 75.3689 and 75.1689 as that is what I would be expecting?

有谁知道为什么我在下面的输出而不是 75.3689 和 75.1689 之间的值,因为这是我所期望的?

(standard_in) 1: syntax error

回答by Gilles Quenot

The first line should looks like :

第一行应如下所示:

randno4=$((RANDOM % 100001))

(( ))is bash arithmetic, with the leading $, the value is substituted : $(( ))

(( ))是 bash 算术,以 开头$,值被替换:$(( ))

When you wrote

当你写

randno4=( )

you try to feed an ARRAY with a arithmetic expression with the wrong syntax.

您尝试使用语法错误的算术表达式为 ARRAY 提供数据。

See http://wiki.bash-hackers.org/syntax/arith_expr

http://wiki.bash-hackers.org/syntax/arith_expr

And finally, like Etan Reisnersaid, You also use $randno3 in the t_twall assignment line which is undefined

最后,就像Etan Reisner所说的,您还在未定义的 t_twall 分配行中使用了 $randno3