shell初学者,不要见笑。请高手帮忙修正一下:
已知问题:
1.不能屏蔽英文字符和符号的输入。
2.减法错误。
一共两个文件,addrobot和numf
addrobot内容:
- #!/bin/sh
- clear
- cat /dev/null > num.txt
- cat /dev/null > numf.txt
- while [ TRUE ]
- do
- clear
- line=`wc -l num.txt|awk '{ print $1 }'`
- sum=`awk 'BEGIN { sum = 0 } { sum = sum + $1} END { OFMT = "%.2f"; print sum/100; }' num.txt`
- tput cup 25 20
- echo $line行 总计:$sum
- tput cup 1 8
- echo ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
- echo -----------------------------------------------------xlink-----------------
- for x in 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
- do
- tput cup $x 4
- echo 数据录入:
- tput cup $x 14
- read num
- if [ $num = q 2>/dev/null ]
- then
- exit
- elif [ -z $num ]
- then
- tput cup $x 14
- echo "非法数值"
- elif [ $num -eq 0 2>/dev/null ]
- then
- tput cup $x 14
- echo "非法数值"
- else
- tput cup $x 40
- echo $num>tmp
- echo $num>>num.txt
- No=`wc -l num.txt|awk '{print $1}'`
- echo No.$No
- line=`wc -l num.txt|awk '{ print $1 }'`
- sum=`awk 'BEGIN { sum = 0 } { sum = sum + $1} END { OFMT = "%.2f"; print sum/100; }' num.txt`
- tput cup 25 20
- echo 共$line行 总计:$sum
- tput cup $x 48
- ./numf
- tput cup $x 14
- fi
- done
- done
复制代码
numf内容:
- #!/bin/sh
- n=`awk '{print length($1)}' tmp`
- if [ $n = 1 ]
- then read num<tmp
- echo 0.0$num
- echo 0.0$num>>numf.txt
- elif [ $n = 2 ]
- then read num<tmp
- echo 0.$num
- echo 0.$num>>numf.txt
- elif [ $n = 3 ]
- then read num<tmp
- na=`echo $num|cut -c1`
- nb=`echo $num|cut -c2-3`
- echo ${na}.${nb}
- echo ${na}.${nb}>>numf.txt
- elif [ $n = 4 ]
- then read num<tmp
- na=`echo $num|cut -c1-2`
- nb=`echo $num|cut -c3-4`
- echo ${na}.${nb}
- echo ${na}.${nb}>>numf.txt
- elif [ $n = 5 ]
- then read num<tmp
- na=`echo $num|cut -c1-3`
- nb=`echo $num|cut -c4-5`
- echo ${na}.${nb}
- echo ${na}.${nb}>>numf.txt
- elif [ $n = 6 ]
- then read num<tmp
- na=`echo $num|cut -c1`
- nb=`echo $num|cut -c2-4`
- nc=`echo $num|cut -c5-6`
- echo ${na},${nb}.${nc}
- echo ${na},${nb}.${nc}>>numf.txt
- elif [ $n = 7 ]
- then read num<tmp
- na=`echo $num|cut -c1-2`
- nb=`echo $num|cut -c3-5`
- nc=`echo $num|cut -c6-7`
- echo ${na},${nb}.${nc}
- echo ${na},${nb}.${nc}>>numf.txt
- elif [ $n = 8 ]
- then read num<tmp
- na=`echo $num|cut -c1-3`
- nb=`echo $num|cut -c4-6`
- nc=`echo $num|cut -c7-8`
- echo ${na},${nb}.${nc}
- echo ${na},${nb}.${nc}>>numf.txt
- elif [ $n = 9 ]
- then read num<tmp
- na=`echo $num|cut -c1`
- nb=`echo $num|cut -c2-4`
- nc=`echo $num|cut -c5-7`
- nd=`echo $num|cut -c8-9`
- echo ${na},${nb},${nc}.${nd}
- echo ${na},${nb},${nc}.${nd}>>numf.txt
- elif [ $n = 10 ]
- then read num<tmp
- na=`echo $num|cut -c1-2`
- nb=`echo $num|cut -c3-5`
- nc=`echo $num|cut -c6-8`
- nd=`echo $num|cut -c9-10`
- echo ${na},${nb},${nc}.${nd}
- echo ${na},${nb},${nc}.${nd}>>numf.txt
- elif [ $n = 11 ]
- then read num<tmp
- na=`echo $num|cut -c1-3`
- nb=`echo $num|cut -c4-6`
- nc=`echo $num|cut -c7-9`
- nd=`echo $num|cut -c10-11`
- echo ${na},${nb},${nc}.${nd}
- echo ${na},${nb},${nc}.${nd}>>numf.txt
- elif [ $n = 12 ]
- then read num<tmp
- na=`echo $num|cut -c1`
- nb=`echo $num|cut -c2-4`
- nc=`echo $num|cut -c5-7`
- nd=`echo $num|cut -c8-10`
- ne=`echo $num|cut -c11-12`
- echo ${na},${nb},${nc},${nd}.${ne}
- echo ${na},${nb},${nc},${nd}.${ne}>>numf.txt
- elif [ $n = 13 ]
- then read num<tmp
- na=`echo $num|cut -c1-2`
- nb=`echo $num|cut -c3-5`
- nc=`echo $num|cut -c6-8`
- nd=`echo $num|cut -c9-11`
- ne=`echo $num|cut -c12-13`
- echo ${na},${nb},${nc},${nd}.${ne}
- echo ${na},${nb},${nc},${nd}.${ne}>>numf.txt
- elif [ $n = 14 ]
- then read num<tmp
- na=`echo $num|cut -c1-3`
- nb=`echo $num|cut -c4-6`
- nc=`echo $num|cut -c7-9`
- nd=`echo $num|cut -c10-12`
- ne=`echo $num|cut -c13-14`
- echo ${na},${nb},${nc},${nd}.${ne}
- echo ${na},${nb}.${nc},${nd}.${ne}>>numf.txt
- else
- :
- fi
复制代码 |