[root@localhost wyb]# cat .sh
#!/bin/bash
#检查给出的字符串是否为回文 read -p "Please input a String:" number
[ -z $number ] && echo "input nothing " && exit len=${#number}
count=$((len/)) for i in `seq $count`
do
lasti=$((len-i+))
first=`echo $number|cut -c $i`
two=`echo $number|cut -c $lasti` [[ "$first" != "$two" ]] && echo no && exit done
echo yes
[root@localhost wyb]# bash .sh
Please input a String:
yes
[root@localhost wyb]# bash .sh
Please input a String:
yes
[root@localhost wyb]# bash .sh
Please input a String:
no
[root@localhost wyb]# bash .sh
Please input a String:
yes
[root@localhost wyb]#
用rev来检查是不是回文
[root@localhost wyb]# cat rev12321.sh
#!/bin/bash
#检查给出的字符串是否为回文
read -p "Please input a String:" number
[ -z $number ] && echo "input nothing " && exit a1=`echo $number|tac`
b2=`echo $number|rev`
[[ "$a1" != "$b2" ]] && echo no || echo yes [root@localhost wyb]# bash rev12321.sh
Please input a String:
no
[root@localhost wyb]# bash rev12321.sh
Please input a String:
yes
[root@localhost wyb]# bash rev12321.sh
Please input a String:
no
[root@localhost wyb]# bash rev12321.sh
Please input a String:
yes
[root@localhost wyb]#

[root@localhost wyb]# cat rev.sh
#!/bin/bash
#检查给出的字符串是否为回文 read -p "Please input a String:" number
[ -z $number ] && echo "input nothing " && exit number2=`echo $number|rev` [[ "$number2" = "$number" ]] && echo yes || echo no
[root@localhost wyb]# bash rev.sh
Please input a String:
yes
[root@localhost wyb]# bash rev.sh
Please input a String:
no
[root@localhost wyb]# bash rev.sh
Please input a String:
yes
[root@localhost wyb]#
 


最新文章

  1. C语言 · 十六进制转十进制
  2. Newtonsoft.Json之JArray, JObject, JPropertyJValue
  3. ubuntu server nginx 安装与配置
  4. Ubuntu下VSFTPD(五)(匿名FTP设置方法)
  5. C# - Environment类,获取桌面的路径
  6. MongoDB系列之三(副本集配置)
  7. 用xml画水平虚线和竖直虚线.md
  8. NYOJ127 星际之门(一)【定理】
  9. 【2017下集美大学软工1412班_助教博客】团队作业9——事后分析(Beta版本)成绩公示
  10. java 类字面常量,泛化的Class引用
  11. 关于opcdaauto.dll的注册
  12. OpenGL笔记(四) API参考
  13. 新装Linux无法访问域名
  14. Git_简介
  15. 沉淀,再出发:jQuery的初步了解和入门
  16. DRP——JDBC中的Batch
  17. C# 超级狗 二次开发 读写数据 激活验证 存储数据库连接字符串
  18. 【09】循序渐进学 docker:docker swarm
  19. django初探-创建简单的博客系统(一)
  20. java将list<T>导出为xls文件

热门文章

  1. laravel 遍历循环
  2. c#实现优先级队列
  3. python 如何在 command 中能够找到 其他module
  4. hyperledger fabric 1.0.5 分布式部署 (二)
  5. java string(转)
  6. JS中一个new到底做了哪些事情?
  7. [HDU1595] find the longest of the shortest
  8. a标签中href=""的几种用法
  9. centos下gitlab的简单安装配置
  10. 116 Populating Next Right Pointers in Each Node 每个节点的右向指针