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!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM