2013-10-15 37 views
0

我知道這是基本問題,但我無法在unix中編寫簡單的添加程序。我使用的cygwin寫的shell腳本我的腳本是這樣的如何在unix中編寫addtion程序

#!/bin/sh 
echo "enter the first number" 
read a 
echo "enter the seconf number" 
read b 
echo [$a + $b] 

回答

0

把兩個數相加,你可以這樣做:

let c = $a + $b 
echo $c 

閱讀,你可以這樣做:

read -p "Enter the first number" a 
read -p "Enter the second number" b 
1
#!/bin/sh 
echo "enter the first number" 
read a 
echo "enter the seconf number" 
read b 
echo $(($a+$b)) 
+0

[文檔參考](http://www.gnu.org/software/bash/manual/bashref.html#Arithmetic-Expansion) –