当前位置:网站首页>验证整数输入
验证整数输入
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
边栏推荐
- Parameter introduction and selection points of wireless module
- TiCDC 架构和数据同步链路解析
- ROS Action communication
- What is the ideal college life?
- Bert usage and word prediction based on Keras_bert model
- Crawler text data cleaning
- 1782. 统计点对的数目 双指针
- Ticmp - 更快的让应用从 MySQL 迁移到 TiDB
- Teach you how to configure Jenkins automated email notifications
- MySQL的安装教程(嗷嗷详细,包教包会~)
猜你喜欢

Path and the largest

What does a software test report contain?

TiDB 在多点数字化零售场景下的应用

想要写出好的测试用例,先要学会测试设计

leetcode-1161:最大层内元素和

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

MySQL (6)

Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化

MySql installation and configuration super detailed tutorial and simple method of building database and table

leetcode-399:除法求值
随机推荐
1782. 统计点对的数目 双指针
勾股数元组 od js
如何在 go 程序中暴露 Prometheus 指标
Distributed. Distributed lock
【genius_platform软件平台开发】第七十四讲:window环境下的静态库和动态库的一些使用方法(VC环境)
Analyze the capabilities and scenarios of the cloud native message flow system Apache Pulsar
MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
934. The Shortest Bridge
My first understanding of MySql, and the basic syntax of DDL and DML and DQL in sql statements
Simple confession page
计算S=a+aa+…+aa…a
有没有可以做副业可以日入300元方法?
数字图像隐写术之卡方分布
tkinter模块高级操作(二)—— 界面切换效果、立体阴影字效果及gif动图的实现
软件测试要达到一个什么水平才能找到一份9K的工作?
Xiaohei's leetcode journey: 104. The maximum depth of a binary tree
设置浏览器滚动条样式
《云原生的本手、妙手和俗手》——2022全国新高考I卷作文
prometheus 监控概述
rpm安装postgresql12