码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2016-08-30 21:08:11      阅读:418      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!