case statement format
case variable in pat1) Execute the statement ;; Fat2) Execute the statement ;; *) Default execution statement ;; esac
Example of use:
Write a shell script, input information, output cpu, mem, disk by prompting the user;
! # / Bin / bash # Display a variety of information #sky-whr cat << EOF menu -------------------------- cpu) display cpu information mem) display memory information disk) displays hard disk information quit) Quit --------------------------- EOF the while : do Read -t . 5 -p " Do you want to view the input: " A IF [- Z $ A]; the then echo " Please enter the correct parameter " echo " such as the CPU, MEM, Disk, quit " be case $a in cpu) cat /proc/cpuinfo ;; mem) free -h ;; disk) fdisk -l ;; quit) break ;; esac done