当前位置:网站首页>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
边栏推荐
- Programmer's debriefing report/summary
- "Cloud native's master, master and vulgar skills" - 2022 National New College Entrance Examination Volume I Composition
- uniapp uses 3rd party fonts
- ROS Action通信
- Multiplication, DFS order
- kotlin中函数作为参数和函数作为返回值实例练习
- [1153]mysql中between的边界范围
- Overview of prometheus monitoring
- leetcode-399: division evaluation
- prometheus 监控概述
猜你喜欢
leetcode-399:除法求值
leetcode-399: division evaluation
Arbitrum 专访 | L2 Summer, 脱颖而出的 Arbitrum 为开发者带来了什么?
leetcode-1161: Maximum in-layer element sum
Shell script to loop through values in log file to sum and calculate average, max and min
C language _ structure pointer array function voting system
ShardingJDBC基本介绍
case语句的综合结果,你究竟会了吗?【Verilog高级教程】
【Map与Set】之LeetCode&牛客练习
What have I experienced when I won the offer of BAT and TMD technical experts?
随机推荐
【Map与Set】之LeetCode&牛客练习
勾股数元组 od js
What have I experienced when I won the offer of BAT and TMD technical experts?
Drools规则属性,高级语法
程序员转正述职报告/总结
SQLserver查询最近三个月的数据,语句该怎么写sqlserver
Software testing basic interface testing - getting started with Jmeter, you should pay attention to these things
【微信小程序】一文带你了解数据绑定、事件绑定以及事件传参、数据同步
keep-alive cache component
Interprocess communication study notes
MySQL的分页你还在使劲的limit?
关于Redis相关内容的基础学习
Kyushu cloud as cloud computing standardization excellent member unit
Google官方控件ShapeableImageView使用
What is the ideal college life?
Arbitrum Interview | L2 Summer, what does the standout Arbitrum bring to developers?
leetcode-128: longest continuous sequence
C语言小程序 -- 常见经典练习题
PDF split/merge
PDF 拆分/合并