当前位置:网站首页>Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 2 Validate input: letters and numbers only
Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 2 Validate input: letters and numbers only
2022-08-09 10:29:00 【Mary Soda Meatloaf】
validalphanum(){validchars="$(echo $1 | sed -e 's/[^[:alnum:]]//g')" #1if [ "$validchars" = "$1" ];thenreturn 0elsereturn 1fi}read -p "Enter input: " input #2if ! validalphanum "$input" ; thenecho "your input must consist only letters and numbers."exit 1elseecho "input is valid"fiexit 0
1.shell script sed tool
sed itself is also a pipe command and can parse standard input.And sed can also replace, delete, add, select specific rows and other functions of data.
[[email protected] ~] sed [-nefr] [action] filename
Options and parameters:
- -n: The general sed command will output all data to the screen.If this option is added, only the lines processed by the sed command will be output to the screen;
- -e: Allows multiple sed command edits to be applied to the input data;
- -f script filename: Read in sed operations from a sed script.Very similar to the -f option of the awk command;
- -r: support extended regular expressions in sed;
- -i: directly modify the file that reads the data with the modification result of sed, instead of outputting the action on the screen
Operation:n1,n2 function
- a : Append, add one or more lines after the current line.
- c : Line replacement, replace the original data line with the string following c.
- i : Insert, insert one or more lines before the current line.
- d: delete, delete the specified line;
- P: print, output the specified line;
- s: String substitution, replace one string with another.The format is "line range s/oldstring/newstring/g" (similar to the replacement format in Vim);
2. Variable keyboard read
$read [-pt] variable
Options and parameters:
-p: can be followed by prompt characters
-t: The number of seconds that can be followed by waiting.
Run result
边栏推荐
- 实现下拉加载更多
- Battery modeling, analysis and optimization (Matlab code implementation)
- 集合与函数
- [相机配置] 海康相机丢包配置环境
- LM小型可编程控制器软件(基于CoDeSys)笔记二十六:plc的数据存储区(模拟量输入通道部分)
- Redis + NodeJS 实现一个能处理海量数据的异步任务队列系统
- 2021-01-11-雪碧图做表情管理器
- OpengGL绘制立方体的三种方法
- Demand side power load forecasting (Matlab code implementation)
- GeoScene Pro 2.1下载地址与安装基本要求
猜你喜欢
随机推荐
MySQL备份与恢复
技术分享 | 如何模拟真实使用场景?mock 技术来帮你
Cpolar内网穿透的面板功能介绍
京东物流与五菱将开发联名版定制产品
Attentional Feature Fusion
UNIX Environment Programming Chapter 15 15.5FIFO
编程技术提升
浅析JWT安全问题
Unix Environment Programming Chapter 14 14.4 I/O Multiplexing
MySQL索引的B+树到底有多高?
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
[相机配置] 海康相机丢包配置环境
OneNote 教程,如何在 OneNote 中搜索和查找笔记?
借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
Win7 远程桌面限制IP
主从postition变化无法锁定_Slave_IO_Running显示No_Slave_Sql_Running显示No---Mysql主从复制同步002
机器学习--朴素贝叶斯(Naive Bayes)
Demand side power load forecasting (Matlab code implementation)
Loop nesting and basic operations on lists
markdown转ipynb--利用包notedown