当前位置:网站首页>Verify the integer input
Verify the integer input
2022-07-31 01:50:00 【my genius girlfriend】
Gets the value of the variable excluding the first digit
${变量#?} Used to get the first value of the variable
number="123"
echo ${number#?}
23
Get the first bit of a variable
KaTeX parse error: Expected '}', got 'EOF' at end of input: {变量%{变量#?}} You can get the first bit of a variable
number="123"
echo ${number%${number#?}}
1
Filter numbers in variables
[[: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 "Please enter the corresponding parameters">&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 "your value is too small,必须大于最小值">&2
return 1
fi
fi
if [ ! -z $max ] ; then
if [ "$number" -gt "$max " ]; then
echo "Your value is too large,必须小于最大值">&2
return 1
fi
fi
return 0
}
if valdint "$1" "$2" "$3" ; then
echo "The number you entered is valid"
fi
边栏推荐
- 类似 MS Project 的项目管理工具有哪些
- 聚簇索引和非聚簇索引到底有什么区别
- Software Testing Defect Reporting - Definition, Composition, Defect Lifecycle, Defect Tracking Post-Production Process, Defect Tracking Process, Purpose of Defect Tracking, Defect Management Tools
- prometheus 监控概述
- Chi-square distribution of digital image steganography
- MySQL的存储过程
- tkinter模块高级操作(二)—— 界面切换效果、立体阴影字效果及gif动图的实现
- Drools规则属性,高级语法
- 1782. Count the number of point pairs Double pointer
- Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
猜你喜欢
基于FPGA的图像实时采集
Arbitrum Interview | L2 Summer, what does the standout Arbitrum bring to developers?
软件测试要达到一个什么水平才能找到一份9K的工作?
[Map and Set] LeetCode & Niu Ke exercise
Are you still working hard on the limit of MySQL paging?
ROS Action communication
Nacos
软件测试报告有哪些内容?
"Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition
Drools规则属性,高级语法
随机推荐
太阳能板最大面积 od js
Centos 7.9安装PostgreSQL14.4步骤
Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化
最大路径和
Interprocess communication study notes
Path and the largest
Likou Daily Question - Day 46 - 704. Binary Search
想要写出好的测试用例,先要学会测试设计
MySQL的分页你还在使劲的limit?
Teach you how to configure Jenkins automated email notifications
Arbitrum 专访 | L2 Summer, 脱颖而出的 Arbitrum 为开发者带来了什么?
Nacos
Jetpack Compose学习(8)——State及remeber
What is the ideal college life?
pycharm cannot run after renaming (error: can't open file...No such file or directory)
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
Distributed. Idempotency
如何在 go 程序中暴露 Prometheus 指标
uniapp使用第三方字体
What does a software test report contain?