标签:read code cat bash other inpu ant 选择 其他
1、case命令选择执行
[root@linuxprobe test]# ls
test.sh
[root@linuxprobe test]# cat test.sh ## 查看脚本
#!/bin/bash
echo "This is a test!"
echo "you can choose 0-9 or a-z or other!!"
read -p "please input what you want to do:" INPUT
case $INPUT in
[0-9])
touch {0..9}.txt
;;
[a-z])
mkdir {a..z}.dir
;;
*)
echo "nothing to do!"
esac
[root@linuxprobe test]# bash test.sh
This is a test!
you can choose 0-9 or a-z or other!!
please input what you want to do:9 ## 执行匹配数字的情况
[root@linuxprobe test]# ls
0.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt test.sh
[root@linuxprobe test]# bash test.sh
This is a test!
you can choose 0-9 or a-z or other!!
please input what you want to do:s ## 执行匹配字母的情况
[root@linuxprobe test]# ls
0.txt 3.txt 6.txt 9.txt c.dir f.dir i.dir l.dir o.dir r.dir test.sh w.dir z.dir
1.txt 4.txt 7.txt a.dir d.dir g.dir j.dir m.dir p.dir s.dir u.dir x.dir
2.txt 5.txt 8.txt b.dir e.dir h.dir k.dir n.dir q.dir t.dir v.dir y.dir
[root@linuxprobe test]# bash test.sh
This is a test!
you can choose 0-9 or a-z or other!! ## 执行匹配其他(*)的情况
please input what you want to do:??!
nothing to do!
标签:read code cat bash other inpu ant 选择 其他
原文地址:https://www.cnblogs.com/liujiaxin2018/p/13839551.html