当前位置:网站首页>验证整数输入
验证整数输入
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
边栏推荐
- Kyushu cloud as cloud computing standardization excellent member unit
- 12张图带你彻底搞懂服务限流、熔断、降级、雪崩
- 什么是理想的大学生活?
- Crypto Life, a day in the life of a Web3 project partner
- 类似 MS Project 的项目管理工具有哪些
- Set the browser scrollbar style
- keep-alive cache component
- TiKV主要内存结构和OOM排查总结
- System design. Short chain system design
- Analyze the capabilities and scenarios of the cloud native message flow system Apache Pulsar
猜你喜欢

What are the project management tools like MS Project

Path and the largest

进程间通信学习笔记

Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值

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

Xiaohei's leetcode journey: 104. The maximum depth of a binary tree

case语句的综合结果,你究竟会了吗?【Verilog高级教程】

leetcode-399:除法求值

Can an inexperienced college graduate switch to software testing?my real case

Overview of prometheus monitoring
随机推荐
C语言小程序 -- 常见经典练习题
两个有序数组间相加和的Topk问题
Arbitrum 专访 | L2 Summer, 脱颖而出的 Arbitrum 为开发者带来了什么?
934. The Shortest Bridge
【Map与Set】之LeetCode&牛客练习
勾股数元组 od js
link与@import的区别
【AcWing 62nd Weekly Game】
coldfusion8后台计划任务拿shell
来自一位女测试工程师的内心独白...
【Mysql】——索引的深度理解
1.非类型模板参数 2.模板的特化 3.继承讲解
最大路径和
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
【flask入门系列】Flask-SQLAlchemy的使用
黄东旭:TiDB的优势是什么?
Likou Daily Question - Day 46 - 704. Binary Search
pycharm cannot run after renaming (error: can't open file...No such file or directory)
C language _ structure pointer array function voting system
汉诺塔问题