第一种方法[[email protected] 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 [[email protected] wyb]# bash 11.sh Please Input a number:1111111122 no [[email protected] wyb]# bash 11.sh Please Input a number:1111111 yes [[email protected] wyb]# bash 11.sh Please Input a number:666666666 yes [[email protected] wyb]# 第二种方法 [[email protected] 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 [[email protected] wyb]# bash 111.sh Please Input a number:111111 yes [[email protected] wyb]# bash 111.sh Please Input a number:123445 no [[email protected] wyb]# bash 111.sh Please Input a number:66666 yes [[email protected] wyb]#
时间: 2024-10-10 23:43:23