当前位置:网站首页>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 01.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] filenameOptions 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] variableOptions and parameters:
-p: can be followed by prompt characters
-t: The number of seconds that can be followed by waiting.
Run result

边栏推荐
猜你喜欢
随机推荐
[贴装专题] 贴装流程中涉及到的位置关系计算
学习NET-SNMP之二-----------VisualStudio编译Net-SNMP
技术分享 | 如何模拟真实使用场景?mock 技术来帮你
抛出一个问题? Mysql环境下进行Count操作执行的时候速度很慢_需手动给主键添加索引---MySql优化001
shell脚本实战(第2版)/人民邮电出版社 脚本1 在PATH中查找程序
踩坑scrollIntoView
How to quickly get through the mirror release process?
day16_03集合
上传张最近做的E2用的xmms的界面的截图
京东物流与五菱将开发联名版定制产品
basic operator
Throwing a question? The execution speed of the Count operation in the Mysql environment is very slow. You need to manually add an index to the primary key---MySql optimization 001
编程技术提升
如何快速打通镜像发布流程?
UNIX Environment Programming Chapter 15 15.5FIFO
stimulus.js 初体验
循环嵌套以及列表的基本操作
xmms的均衡器试验成功 音效相当不错 比rockbox可能还要好
snmp++编译错误问题解决方法
[项目配置] 配置Qt函数库和ui界面库的封装并调用的项目









