使用变量编写脚本无效?

Cra*_*aig 1 unix variables bash shell scripting

我正在尝试学习一些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
Run Code Online (Sandbox Code Playgroud)

这是展示的内容.

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
Run Code Online (Sandbox Code Playgroud)

Jon*_*ler 5

在一个/bin/shBash(Mac OS X 10.9.2 Mavericks)系统上,我得到:

$ cat 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
$ sh math
5 10 15 5 50 0
$ bash math
5 10 15 5 50 0
$ ksh math
5 10 15 5 50 0
$ dash math
math: 3: math: let: not found
math: 4: math: let: not found
math: 5: math: let: not found
math: 6: math: let: not found
5 10
$ hsh math
math: let: not found
math: let: not found
math: let: not found
math: let: not found
5 10
$
Run Code Online (Sandbox Code Playgroud)

(hsh是作为另一个名字安装的传家宝Bourne Shell.)

这意味着,无论sh mathbash math做算术,你打算.您是否可能在具有不同shell的计算机上/bin/sh(可能是dash伪装而且您使用的是Ubuntu)?