#!/bin/sh
# calculate the sum from 1 to n
# validate the varibles number
if [ $# -ne 2 ] ; then
echo "usage : sum.sh start end"
exit
fi
start=$1
end=$2
while [ $start -lt $end ]
do
sum=$sum+$start
echo "$sum"
start=$start+1
done
echo "the result is $sum"
# calculate the sum from 1 to n
# validate the varibles number
if [ $# -ne 2 ] ; then
echo "usage : sum.sh start end"
exit
fi
start=$1
end=$2
while [ $start -lt $end ]
do
sum=$sum+$start
echo "$sum"
start=$start+1
done
echo "the result is $sum"
本文介绍了一个简单的Shell脚本,该脚本可以接收两个参数并计算从第一个参数到第二个参数之间的所有整数之和。通过使用while循环和基本的算术运算,此脚本展示了如何在Shell中进行数值计算。
977

被折叠的 条评论
为什么被折叠?



