当前位置:网站首页>验证整数输入
验证整数输入
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
边栏推荐
猜你喜欢
[Map and Set] LeetCode & Niu Ke exercise
Interprocess communication study notes
"Real" emotions dictionary based on the text sentiment analysis and LDA theme analysis
Chi-square distribution of digital image steganography
What have I experienced to become a tester who is harder than development?
16、注册中心-consul
VSCode Plugin: Nested Comments
Overview of prometheus monitoring
软件测试报告有哪些内容?
Google官方控件ShapeableImageView使用
随机推荐
CV-Model [3]: MobileNet v2
【AcWing 62nd Weekly Game】
What does a software test report contain?
rpm安装postgresql12
Likou Daily Question - Day 46 - 704. Binary Search
MySQL (6)
VSCode插件:嵌套注释
Fiddler抓包模拟弱网络环境测试
934. The Shortest Bridge
MySql installation and configuration super detailed tutorial and simple method of building database and table
汉诺塔问题
【Mysql】——索引的深度理解
uniapp uses 3rd party fonts
【Map与Set】之LeetCode&牛客练习
TiCDC 架构和数据同步链路解析
数字图像隐写术之JPEG 隐写分析
用户交互+格式化输出
想要写出好的测试用例,先要学会测试设计
数字图像隐写术之卡方分布
Path and the largest