当前位置:网站首页>验证整数输入
验证整数输入
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
边栏推荐
- 软件测试工作3年了,谈谈我是如何从刚入门进阶到自动化测试的?
- PDF 拆分/合并
- Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
- 数字图像隐写术之卡方分布
- 充电效果模拟
- uniapp uses 3rd party fonts
- Gateway路由的配置方式
- The difference between 4G communication module CAT1 and CAT4
- GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
- 一个无经验的大学毕业生,可以转行做软件测试吗?我的真实案例
猜你喜欢
软件测试报告有哪些内容?
观察者(observer)模式(一)
VSCode Plugin: Nested Comments
Multiplication, DFS order
【Mysql】——索引的深度理解
"Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition
MySQL (6)
Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
Centos 7.9 install PostgreSQL14.4 steps
Distributed. Idempotency
随机推荐
数字图像隐写术之JPEG 隐写分析
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
什么是理想的大学生活?
软件测试要达到一个什么水平才能找到一份9K的工作?
TiDB 操作实践 -- 备份与恢复
leetcode-399:除法求值
内网渗透——提权
计算S=a+aa+…+aa…a
12张图带你彻底搞懂服务限流、熔断、降级、雪崩
软件测试基础接口测试-入门Jmeter,你要注意这些事
GCC Rust获批将被纳入主线代码库,或将于GCC 13中与大家见面
Shell变量与赋值、变量运算、特殊变量
rpm安装postgresql12
九州云获评云计算标准化优秀成员单位
coldfusion文件读取漏洞(CVE-2010-2861)
16、注册中心-consul
想要写出好的测试用例,先要学会测试设计
如何在 go 程序中暴露 Prometheus 指标
MySQL stored procedure
Is there a way to earn 300 yuan a day by doing a side business?