当前位置:网站首页>验证整数输入
验证整数输入
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
边栏推荐
猜你喜欢

成为比开发硬气的测试人,我都经历了什么?

最高月薪20K?平均薪资近万...在华为子公司工作是什么体验?

VSCode Plugin: Nested Comments

Word 表格跨页,仍然显示标题

Path and the largest

12 pictures take you to fully understand service current limit, circuit breaker, downgrade, and avalanche

【微信小程序】一文带你了解数据绑定、事件绑定以及事件传参、数据同步

Analyze the capabilities and scenarios of the cloud native message flow system Apache Pulsar

"Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition

leetcode-399: division evaluation
随机推荐
Kyushu cloud as cloud computing standardization excellent member unit
数字图像隐写术之卡方分布
最大路径和
Interprocess communication study notes
android的webview缓存相关知识收集
类似 MS Project 的项目管理工具有哪些
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
TiDB 操作实践 -- 备份与恢复
leetcode-952:按公因数计算最大组件大小
聚簇索引和非聚簇索引到底有什么区别
初识C语言 -- 数组
【AcWing 62nd Weekly Game】
软件测试报告有哪些内容?
Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
Analyze the capabilities and scenarios of the cloud native message flow system Apache Pulsar
【flask入门系列】Flask-SQLAlchemy的使用
[Map and Set] LeetCode & Niu Ke exercise
九州云入选“可信云最新评估体系及2022年通过评估企业名单”
程序员转正述职报告/总结
C语言_结构体指针数组函数选票系统