shell练习五
2015-08-29 00:00
375 查看
摘要: shell练习五--检查输入的ip是否正确
写一个shell检查我们输入的IP是否属于正确的格式
写一个shell检查我们输入的IP是否属于正确的格式
#! /bin/bash checkip() { if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' ; then a=`echo $1 | awk -F. '{print $1}'` b=`echo $1 | awk -F. '{print $2}'` c=`echo $1 | awk -F. '{print $3}'` d=`echo $1 | awk -F. '{print $4}'` for n in $a $b $c $d; do if [ $n -ge 255 ] || [ $n -le 0 ]; then echo "the number of the IP should less than 255 and greate than 0" return 2 fi done else echo "The IP you input is something wrong, the format is like 192.168.100.1" return 1 fi } rs=1 while [ $rs -gt 0 ]; do read -p "Please input the ip:" ip checkip $ip rs=`echo $?` done echo "The IP is right!"
[root@localhost shell]# sh check.sh Please input the ip:192.168.1.1 The IP is right! [root@localhost shell]# sh check.sh Please input the ip:1234.123.12.1 The IP you input is something wrong, the format is like 192.168.100.1 Please input the ip:192.168.1.1 The IP is right!
相关文章推荐
- Spark的Python和Scala shell介绍(翻译自Learning.Spark.Lightning-Fast.Big.Data.Analysis)
- Linux生产服务器Shell脚本分享
- hive shell命令
- 希尔排序(shell)
- Shell 脚本面试问题大全
- 一个Linux中用于监控的简易shell脚本
- 关于shell中的正则表达式和awk的使用
- SSH隧道管理内部服务(putty,ssh secure shell)for win
- adb 连不上设备的种种情况
- bash: ifconfig: command not found 解决办法
- Shell scripts to Create a local dir base on the time.
- 小议:如何用PowerShell创建State Services?
- HBase shell 无法使用 Backspace 键-解决方案
- linux shell if 参数
- linuxSHELL学习之获取用户输入
- xshell远程qemu-kvm虚拟机安装
- Linux shell获取时间和时间间隔(ms级别)
- 《Linux命令、编辑器与Shell编程》读书笔记3-linux命令中的特殊字符和正则表达式
- xshell5连接centos6.7时提示服务器拒绝了密码的解决办法
- 收集的48个Shell脚本小技巧