【发布时间】:2014-05-03 10:47:26
【问题描述】:
我正在尝试学习一些 unix,并且正在尝试编写一些基本变量的脚本,知道为什么在我进行数学运算时这不起作用吗?
> vi math
A=5
B=10
let C=A+B
let D=B-A
let E=A*B
let F=A/B
echo $A $B $C $D $E $F
这是显示的内容。
math: 4: math: let: not found
math: 5: math: let: not found
math: 6: math: let: not found
math: 7: math: let: not found
5 10
【问题讨论】:
-
什么不起作用?您应该使用 bash 使用
bash ./math运行它 -
现代 POSIX 标准的数学运算方法是
C=$((A+B))。let是过去时代的遗物。 -
...另外,“不起作用”并不是很有用。如果您准确地描述了它的作用,那会让人们更有帮助。
-
您的输出与我在使用
dash时看到的相同。你能显示输出:bash math,然后是sh math,然后是dash math?我希望sh math的输出与dash math的输出相同。 -
是的,当我做 Bash 数学时它可以工作... > sh math math: 4: math: let: not found math: 5: math: let: not found math: 6: math: let :未找到数学:7:数学:让:未找到 5 10 > bash 数学 5 10 15 5 50 0 > 破折号数学数学:4:数学:让:未找到数学:5:数学:让:未找到数学:6 : math: let: not found math: 7: math: let: not found 5 10
标签: bash shell variables unix scripting