微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux系统中case命令用法

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!

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。