当前位置:网站首页>验证整数输入
验证整数输入
2022-07-31 01:47:00 【我的天才女友】
获取变量除第一位的值
${变量#?} 用来获取变量的出第一位的值
number="123"
echo ${number#?}
23
获取变量的第一位
KaTeX parse error: Expected '}', got 'EOF' at end of input: {变量%{变量#?}} 可以获取变量的第一位
number="123"
echo ${number%${number#?}}
1
过滤变量中的数字
[[:digit:]]表示数字
echo $testvalue | sed ‘s/[[:digit:]]//g’
判断变量是否为空
-z 判断变量是否为空, 为空则返回true
if [ ! -z $nodigits ]
#!/bin/bash
valdint(){
number="$1"; min="$2"; max="$3"
if [ -z $number ]; then
echo "请你输入对应的参数">&2
return 1
fi
if [ "${number%${number#?}}" = "-" ]; then
testvalue="${number#?}"
else
testvalue="$number"
fi
nodigits="$(echo $testvalue | sed 's/[[:digit:]]//g' )"
if [ ! -z $nodigits ]; then
echo "只能输入数字">&2
return 1
fi
if [ ! -z $min ] ; then
if [ "$number" -lt "$min" ]; then
echo "你的值太小,必须大于最小值">&2
return 1
fi
fi
if [ ! -z $max ] ; then
if [ "$number" -gt "$max " ]; then
echo "你的值太大,必须小于最大值">&2
return 1
fi
fi
return 0
}
if valdint "$1" "$2" "$3" ; then
echo "你输入的数字合格"
fi
边栏推荐
- leetcode-399: division evaluation
- The Meta Metaverse Division lost 2.8 billion in the second quarter, still want to continue to bet?Metaverse development has yet to see a way out
- 观察者(observer)模式(一)
- 16、注册中心-consul
- leetcode-952: Calculate max component size by common factor
- "Real" emotions dictionary based on the text sentiment analysis and LDA theme analysis
- ROS Action通信
- Meta元宇宙部门第二季度亏损28亿 仍要继续押注?元宇宙发展尚未看到出路
- Nacos
- 《云原生的本手、妙手和俗手》——2022全国新高考I卷作文
猜你喜欢
进程间通信学习笔记
"Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition
VSCode Plugin: Nested Comments
软件测试要达到一个什么水平才能找到一份9K的工作?
黄东旭:TiDB的优势是什么?
1782. 统计点对的数目 双指针
12 pictures take you to fully understand service current limit, circuit breaker, downgrade, and avalanche
What have I experienced to become a tester who is harder than development?
prometheus 监控概述
MySQL (6)
随机推荐
Simple confession page
Chi-square distribution of digital image steganography
MySql installation and configuration super detailed tutorial and simple method of building database and table
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
CV-Model【3】:MobileNet v2
kotlin中函数作为参数和函数作为返回值实例练习
Arbitrum Interview | L2 Summer, what does the standout Arbitrum bring to developers?
Basic Parameters of RF Devices 1
Ticmp - 更快的让应用从 MySQL 迁移到 TiDB
成为比开发硬气的测试人,我都经历了什么?
link与@import的区别
Is there a way to earn 300 yuan a day by doing a side business?
I have been working in software testing for 3 years, how did I go from just getting started to automated testing?
leetcode-1161: Maximum in-layer element sum
蛮力法/邻接表 广度优先 有向带权图 无向带权图
PDF split/merge
数字图像隐写术之JPEG 隐写分析
C语言小程序 -- 常见经典练习题
PDF 拆分/合并
MySql的安装配置超详细教程与简单的建库建表方法