select VAR in LIST
do
command1
command2
... ...
commandN
done
select循环语句有如下的特点:
#########################################################################
# File Name: OS_Info.sh
# Author: Toney Sun
# mail: vip_13031075266@163.com
# Created Time: 2020年04月25日 星期六 22时30分31秒
#########################################################################
#!/bin/bash
PS3="your choice is [5 for quit ]: "
while :
do
select choice in disk_partion filesystem cpu_load mem_util quit
do
case "$choice" in
disk_partion)
#显示磁盘分区信息
fdisk -l
break;
;;
filesystem)
#查看磁盘的使用率
df -h
break;
;;
cpu_load)
#查看CPU的使用率
uptime
break;
;;
mem_util)
#查看内存使用情况
free -m
break;
;;
quit)
exit
;;
*)
echo "Input error!!!"
;;
esac
echo "------------------------------------------"
done
done
脚本的运行结果如下:
root@ubantu:/mnt/hgfs/em嵌入式学习记录/shell# ./systemInfo.sh
1) disk_partion 3) cpu_load 5) quit
2) filesystem 4) mem_util
your choice is [5 for quit ]: 2
Filesystem Size Used Avail Use% Mounted on
udev 946M 0 946M 0% /dev
tmpfs 196M 1.8M 195M 1% /run
/dev/sda1 20G 15G 3.9G 80% /
tmpfs 980M 0 980M 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 980M 0 980M 0% /sys/fs/cgroup
/dev/loop1 15M 15M 0 100% /snap/gnome-logs/45
/dev/loop0 15M 15M 0 100% /snap/gnome-characters/495
/dev/loop2 94M 94M 0 100% /snap/core/9066
/dev/loop3 141M 141M 0 100% /snap/gnome-3-26-1604/98
/dev/loop4 2.3M 2.3M 0 100% /snap/gnome-calculator/260
/dev/loop5 63M 63M 0 100% /snap/gtk-common-themes/1506
/dev/loop8 3.8M 3.8M 0 100% /snap/gnome-system-monitor/57
/dev/loop6 3.8M 3.8M 0 100% /snap/gnome-system-monitor/135
/dev/loop7 141M 141M 0 100% /snap/gnome-3-26-1604/74
/dev/loop9 219M 219M 0 100% /snap/nextcloud/20007
/dev/loop11 13M 13M 0 100% /snap/gnome-characters/139
/dev/loop10 161M 161M 0 100% /snap/gnome-3-28-1804/116
/dev/loop12 55M 55M 0 100% /snap/gtk-common-themes/1502
/dev/loop13 94M 94M 0 100% /snap/core/8935
/dev/loop14 1.0M 1.0M 0 100% /snap/gnome-logs/93
/dev/loop16 4.4M 4.4M 0 100% /snap/gnome-calculator/704
/dev/loop15 55M 55M 0 100% /snap/core18/1705
vmhgfs-fuse 489G 35G 454G 8% /mnt/hgfs
tmpfs 196M 16K 196M 1% /run/user/121
tmpfs 196M 36K 196M 1% /run/user/1000
/dev/sr0 1.9G 1.9G 0 100% /media/toney/Ubuntu 18.04.2 LTS amd64
tmpfs 196M 0 196M 0% /run/user/0
/dev/loop17 233M 233M 0 100% /snap/nextcloud/20498
1) disk_partion 3) cpu_load 5) quit
2) filesystem 4) mem_util
your choice is [5 for quit ]:
手机扫一扫
移动阅读更方便
你可能感兴趣的文章