Linux 编写俩个Shell程序kk和aa,在kk中输入俩个数,调用aa计算这俩个数之间奇数的和

如题所述

一个文件能写的,为什么要写成两个文件?

#!/bin/bash
read -p "Please enter the first number:" num1
read -p "Please enter the second number:" num2
c=0
if [ $num1 -gt $num2 ]
then
i="$num2"
j="$num1"
else
i="$num1"
j="$num2"
fi
while [ $i -le $j ]
do
if [ `expr $i % 2` -ne 0 ]
then
c=`expr $i + $c`
fi
i=`expr $i + 1`
done

echo " $num1 ~ $num2 之间奇数之和为:$c"追问

这是道题 我也不知道为什么要写俩文件

追答

估计目的是让你们练习传递参数。
自己改改吧。很容易的饿。

追问

我试了试 不能运行啊

追答

[flycat@redhat ~]$ ./js.sh
Please enter the first number:20
Please enter the second number:100
20~ 100 之间奇数之和为:2400
[flycat@redhat ~]$

你报什么错啊,可以运行啊。

追问

谢谢啦 我知道了

温馨提示:答案为网友推荐,仅供参考
相似回答