首页 > 系统服务 > 详细

shell脚本,判断给出的字符串是否相等。

时间:2016-08-30 21:06:30      阅读:1185      评论:0      收藏:0      [点我收藏+]
第一种方法
[root@localhost wyb]# cat 11.sh #!/bin/bash #判断给出的字符串是否相等 read -p "Please Input a number:" number [ -z $number ] && echo Input nothing && exit 1 len=${#number} a=`echo $number|cut -c 1` for i in `seq $len` do b=`echo $number|cut -c $i` [[ "$a" != "$b" ]] && echo no && exit done echo yes [root@localhost wyb]# bash 11.sh Please Input a number:1111111122 no [root@localhost wyb]# bash 11.sh Please Input a number:1111111 yes [root@localhost wyb]# bash 11.sh Please Input a number:666666666 yes [root@localhost wyb]#

第二种方法 [root@localhost wyb]#
cat 111.sh #!/bin/bash #判断给出的字符串是否相等 read -p "Please Input a number:" number [ -z $number ] && echo Input nothing && exit 1 a=`echo $number|cut -c 1` b=`echo $number|tr -d $a` [ -z $b ] && echo yes || echo no [root@localhost wyb]# bash 111.sh Please Input a number:111111 yes [root@localhost wyb]# bash 111.sh Please Input a number:123445 no [root@localhost wyb]# bash 111.sh Please Input a number:66666 yes [root@localhost wyb]#

 

shell脚本,判断给出的字符串是否相等。

原文:http://www.cnblogs.com/wangyuebo/p/5823544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!