The example given here is to verify the user information is input numbers and letters. It should be noted that the reason for it to be collected in the series, mainly because of the way it implements the tricky part.
[root@xieqichao ~]# cat > test15.sh#!/bin/shecho -n "Enter your input: "read input
#1. 事实上,这里的巧妙之处就是先用sed替换了非法部分,之后再将替换后的结果与原字符串比较。这种写法也比较容易扩展。
parsed_input=`echo $input |sed's/[^[:alnum:]]//g'`if["$parsed_input"!="$input"];thenecho"Your input must consist of only letters and numbers."elseecho"Input is OK."fi
CTRL+D
[root@xieqichao ~]# ./test15.sh
Enter your input: hello123
Input is OK.
[root@xieqichao ~]# ./test15.sh
Enter your input: hello world
Your input must consist of only letters and numbers.
```