本人只在SCO OpenServer 5.0.6 & Ksh 环境下调试过,其他平台自行测试。
脚本内容如下:
#!/bin/ksh # ksh环境下控制字符串输入的shell # 仙桃市农村信用合作联社 吕永辉 getcon(){ stty raw -echo TempC=`dd if=/dev/tty bs=1 count=1 2>/dev/null | od -b | sed '$d' | awk '{printf("obase=10;ibase=8;%d\n",$2)}' | bc` stty -raw echo $TempC } get_str(){ # 参数:1-长度 2-提示行 3-纵坐标 4-变量名 5-是否可空 eval $4="" set -A StrT while i=0 echo "[${3};3H`printf "%-10s[%$1s]" ${2} ' '`" > /dev/tty echo "[${3};14H\c" > /dev/tty while [ "$i" = "$1" ] && break stty -echo C_Code=`getcon` case $C_Code in 13|127) break;; # 回车、跳出 27)stty min 0 time 1;C_Code=`getcon`;stty min 1 time 1 #处理功能键序列 [ $C_Code -eq 91 ] && { C_Code=`getcon` case $C_Code in 65)C_Code=27;C_Fun=Up;break;; 66)C_Code=27;C_Fun=Down;break;; 67)C_Code=27;C_Fun=Right;break;; 68)C_Code=27;C_Fun=Left;break;; 71)C_Code=27;C_Fun=PgUp;break;; 73)C_Code=27;C_Fun=PgDn;break;; *)C_Code=13;break;; esac }||{ C_Code=27;C_Fun=ESC;break };; 60|61|62|63|91|92|93|123|124|125) continue;; # 屏蔽限制字符 esac [ $C_Code -eq 8 ] && { [ i -eq 0 ] && { echo "[${3};`expr 14 + $i`H\c" > /dev/tty continue } j=`expr $i - 1` [ "${StrT[$j]}" = "" ] && { StrT[$i]="" StrT[$j]="" i=`expr $j - 1` StrT[$i]="" echo "[${3};`expr 14 + $i`H \c" > /dev/tty echo "[${3};`expr 14 + $i`H\c" > /dev/tty }||{ StrT[$i]="" i=`expr $i - 1` StrT[$i]="" echo "[${3};`expr 14 + $i`H \c" > /dev/tty echo "[${3};`expr 14 + $i`H\c" > /dev/tty } continue } [ $C_Code -lt 43 ] && continue # 屏蔽特殊字符 StrT[$i]="`echo $C_Code| awk '{printf("%c\n",$1)}'`" [ "${StrT[$i]}" = " " -o "${StrT[$i]}" = "" ] && continue [ $C_Code -gt 128 ] && { StrA=`echo -n ${StrT[$i]}` j=`echo -n $i` i=`expr $i + 1` [ "$i" = "$1" ] && { StrT[$j]="" i=`expr $i - 1` echo -n "[${3};`expr 14 + $j`H ]" > /dev/tty echo "[${3};`expr 14 + $j`H\c" > /dev/tty continue } || { C_Code=`getcon` StrT[$i]="`echo $C_Code| awk '{printf("%c\n",$1)}'`" StrT[$j]=`echo -n ${StrA}${StrT[$i]}` StrT[$i]="" } } C_Str=`echo ${StrT[*]} | sed 's/ //g'` stty echo echo "[${3};14H${C_Str}\c" > /dev/tty do i=`expr $i + 1` done do [ $C_Code -eq 127 -o $C_Code -eq 27 ] && { # 、丢弃输入还未处理功能键序列 [ $5 -eq 1 ] && { C_Str='';continue }||{ stty echo;eval $4="";break } } [ $C_Code -eq 13 ] && { [ $5 -eq 1 -a "$C_Str" = "" ] && { continue }||{ stty echo;eval $4=`echo -n $C_Str`;C_Str="";break } } [ "$i" = "$1" ] && { stty echo;eval $4=`echo -n $C_Str`;C_Str="";break } C_Str='' set -A StrT done } # get_str 参数:1-长度 2-标题 3-纵坐标 4-变量名 5-是否可空 clear conI=5 get_str 2 机构号 $conI InstNo 1 conI=`expr $conI + 1` get_str 1 资产主类 $conI AssetsClass 1 conI=`expr $conI + 1` get_str 30 资产名称 $conI AssetsName 1 conI=`expr $conI + 1` get_str 30 建筑物地址 $conI AssetsAdd 0 conI=`expr $conI + 1` get_str 20 房产证号码 $conI AbstractTitle 0 conI=`expr $conI + 1` get_str 20 土地证号码 $conI TenureTitle 0 conI=`expr $conI + 1` get_str 10 保管人 $conI Custodian 0 conI=`expr $conI + 1` get_str 60 备注 $conI Remark 0 echo "\n $AssetsClass $InstNo $AssetsName \n 地址:$AssetsAdd \n 房产证号:$AbstractTitle \n土地证号:$TenureTitle 保管人:$Custodian \n 备注:$Remark"
|
文件: |
getstr.tar |
大小: |
5KB |
下载: |
下载 | | |
阅读(1285) | 评论(0) | 转发(0) |