【问题标题】:How to write addtion program in unix [duplicate]如何在unix中编写addtion程序[重复]
【发布时间】:2013-12-04 21:57:05
【问题描述】:

我知道这是基本问题,但我无法在 unix 中编写简单的加法程序。我正在使用 cygwin 编写 shell 脚本 我的脚本是这样的

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

【问题讨论】:

    标签: unix


    【解决方案1】:
    #!/bin/sh
    echo "enter the first number"
    read a
    echo "enter the seconf number"
    read b
    echo  $(($a+$b))
    

    【讨论】:

    【解决方案2】:

    要添加两个数字,您可以这样做:

    let c = $a + $b
    echo $c
    

    要阅读,你可以这样做:

    read -p "Enter the first number" a
    read -p "Enter the second number" b
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-27
      • 2012-08-30
      • 2012-04-12
      • 1970-01-01
      • 2010-10-19
      • 2014-03-21
      • 1970-01-01
      • 2011-07-05
      相关资源
      最近更新 更多