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!
复制代码

 

posted @   小鲨鱼2018  阅读(1162)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示