分页: 1 / 1

shell小程序每行加下注释

发表于 : 2012-01-04 15:27
zy364628589
刚大三,初学Linux,希望各位大大为下面两段程序每行加一下注释,方便看懂,谢谢。
第一个是一个函数,可以计算任意个正整数的和,如果输入错误就返回-1

#!/bin/bash
# mysum
sum=0;
function mysum(){
while [ $# -ne 0 ]
do
if [ `echo $1 | grep "^[0-9][0-9]*$"` ]
then
sum=$(expr $sum + $1)
shift
else
sum=-1
break
fi

done
echo $sum
}
然后是一个简单的通讯录程序
#!/bin/bash
#
# MENU
#

function find()
{
echo "input Name:"
read name
cat data.txt |grep "^$name"
read a
}

function add()
{
echo "input Name:"
read name
echo "input Number:"
read number
te="$name $number"
echo $te
echo $te >>data.txt
read a

}
function Edit()
{
echo "input Old Name:"
read nameo
echo "input New Name:"
read namen
echo "input Old Number:"
read numbero
echo "input New Number:"
read numbern
teo="$nameo $numbero"
ten="$namen $numbern"
sed '/$teo/d' data.txt
echo $ten >>data.txt
}



if [ -f data.txt ]
then
echo
else
"">>data.txt
fi

while ls > /dev/null 2>&1
do
clear
echo
echo
echo
echo
echo " 1: Show Date and Time"
echo " 2: Find Phone Number"
echo " 3: Add Phone Number Record"
echo " 4: Edit Phone Number Record"
echo " 5: Exit"
echo -e "Enter your choice: \c"
read option
case $option in
1) date
read $a;;
2) echo "Finding...";
find;;
3) echo "Add...";add ;;
4) echo "Editing...";Edit ;;
5) echo "Bye...";break ;;
*) echo "Invalid input";;
esac
echo
done

Re: shell小程序每行加下注释

发表于 : 2012-01-05 8:48
ChenFengyuan
zy364628589 写了:希望各位大大为下面两段程序每行加一下注释,方便看懂,谢谢。
:em20 :em20 :em20

Re: shell小程序每行加下注释

发表于 : 2012-01-05 8:54
josephyoung
:em20 这要求太目中无人了吧

Re: shell小程序每行加下注释

发表于 : 2012-01-06 22:02
linuxunion
既然是初学,还是先弄点自己看得懂的吧。不要太为难自己!

Re: shell小程序每行加下注释

发表于 : 2012-01-07 15:59
枫叶饭团
我们学校计算机专业的好像有这么个作业,我已经帮别人做过三份了。计算机学院的找通信学院的做计算机作业,我想着就搞笑

Re: shell小程序每行加下注释

发表于 : 2012-01-07 16:58
daf3707
echo
是回显
一人帮一行 :em05

Re: shell小程序每行加下注释

发表于 : 2012-01-08 13:18
tusooa
自己写的脚本,居然自己看不懂 :em20 :em20 :em20
还有,为啥while ls?