当前位置:网站首页>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
边栏推荐
- 主从postition变化无法锁定_Slave_IO_Running显示No_Slave_Sql_Running显示No---Mysql主从复制同步002
- 小程序员的发展计划
- 元组 字典 集合
- 壁纸
- Unix Environment Programming Chapter 15 15.9 Shared Storage
- 深度学习--自编码器(AutoEncoder)
- VBA实战(11) - 工作表(Sheet) 操作汇总
- Dialogue with the DPO of a multinational consumer brand: How to start with data security compliance?See you on 8.11 Live!
- 1004 成绩排名 (20 分)
- shell脚本实战(第2版)/人民邮电出版社 脚本1 在PATH中查找程序
猜你喜欢
Probably 95% of the people are still making PyTorch mistakes
阿里神作!吃透这份资料入厂率高达99%
【MySQL】mysql因为字符集导致left join出现Using join buffer (Block Nested Loop)
想了解API接口,这一篇就够了
机器学习-逻辑回归(logistics regression)
【报错记录】解决华擎J3455-ITX不插显示器无法开机的问题
强化学习 (Reinforcement Learning)
可能95%的人还在犯的PyTorch错误
深度学习--生成对抗网络(Generative Adversarial Nets)
ESIM(Enhanced Sequential Inference Model)- 模型详解
随机推荐
机器学习-逻辑回归(logistics regression)
好久没更新博客了
实现下拉加载更多
day16_03集合
MySQL全文索引
【原创】解决阿里云oss-browser.exe双击没反应打不开,提供一种解决方案
markdown转ipynb--利用包notedown
Attentional Feature Fusion
Nodejs服务端
机器学习--朴素贝叶斯(Naive Bayes)
Qt 国际化翻译
深度学习--神经网络(基础讲解)
TELNET协议相关RFC
UNIX Environment Programming Chapter 15 15.5FIFO
Redis + NodeJS 实现一个能处理海量数据的异步任务队列系统
OpenGL ES2.0编程三部曲(转载自MyArrow)
MySQL索引的B+树到底有多高?
[贴装专题] 贴装流程中涉及到的位置关系计算
MySQL和MyEclipse的数据库连接操作
The GNU Privacy Guard