Shell脚本写的简单字符串hash函数
2011-09-09 14:33
399 查看
#!/bin/bash Letter2Int(){ if [ "$#" -ne "0" ]; then echo "Letter2Int Wrong Paramenters!" >&2 return 1 fi read letter length=`echo $letter|awk '{printf("%d", length($0))}'` if [ "$length" -ne "1" ]; then echo "Letter2Int: more than one letter: $letter!" >&2 return 1 fi printf "%d" "'$letter" return 0 } Hash(){ if [ "$#" -ne "1" ]; then echo "Hash Wrong Paramenters!" >&2 return 1 fi read string length=`echo $string|awk '{printf("%d", length($0))}'` if [ "$length" -eq "0" ]; then echo "Hash: At least one letter should be input!" >&2 return 1 fi iCount=1 letterSum=0 while [ "$iCount" -le "$length" ] do letterCur=`expr substr $string $iCount 1` letterNumCur=`printf "%d" "'$letterCur"` echo "$letterCur $letterNumCur" letterSum=`expr $letterSum + $letterNumCur` iCount=`expr $iCount + 1` done echo $letterSum letterSum=`expr $letterSum % $1` echo $letterSum return 0 } read letter echo $letter|Hash 10
相关文章推荐
- Shell脚本实现简单分割字符串
- 一个典型的简单shell字符串处理脚本
- Shell脚本实现简单分割字符串
- shell脚本简单切割字符串
- 脚本乐园 Shell字符串比较相等、不相等方法小结
- 简单的远程FTP定时备份Shell脚本分享
- 【shell脚本练习】网卡信息和简单日志分析
- 如何编写一个简单的shell脚本.task3用到的脚本
- 一些简单的shell脚本实例
- Shell脚本字符串单引号和双引号的区别浅析
- vbs wscript.shell objShell.Run 字符串 脚本 定时监控链路质量并保存
- shell脚本--if判断(数字条件、字符串条件)
- Shell脚本截取字符串的方法
- SHELL 简单脚本 更新中
- 自动化运维-使用Shell脚本简单实现
- shell 最简单最牛逼的备份脚本!!
- 简单shell脚本记录(整理中)
- shell脚本简单语法
- 使用shell 脚本做简单的压力测试
- Linux下C语言引用shell脚本的简单例子