系统信息显示脚本

LinuxLinuxIntermediate
立即练习

💡 本教程由 AI 辅助翻译自英文原版。如需查看原文,您可以 切换至英文原版

简介

sysInfo.sh 脚本旨在根据用户的选择向用户显示各种系统信息。该脚本为用户提供了一个菜单供其选择,并使用 switch case 语句来显示所选选项的输出。显示的信息包括当前登录的用户、shell 目录、主目录、操作系统名称和版本、当前工作目录、登录用户数量、系统中可用的 shell、硬盘信息、CPU 信息、内存信息、文件系统信息以及当前正在运行的进程。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/FileandDirectoryManagementGroup(["File and Directory Management"]) linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux/FileandDirectoryManagementGroup -.-> linux/pwd("Directory Displaying") linux/SystemInformationandMonitoringGroup -.-> linux/uname("System Information Displaying") linux/UserandGroupManagementGroup -.-> linux/whoami("User Identifying") subgraph Lab Skills linux/pwd -.-> lab-18281{{"系统信息显示脚本"}} linux/uname -.-> lab-18281{{"系统信息显示脚本"}} linux/whoami -.-> lab-18281{{"系统信息显示脚本"}} end

系统信息

在这个挑战中,你需要创建一个脚本,根据用户输入显示各种系统信息。

任务

你需要完成以下任务:

  1. 创建一个脚本,根据用户输入显示各种系统信息。
  2. 使用 switch case 语句处理用户输入并显示相应的系统信息。

要求

你必须满足以下要求:

  • 将脚本命名为 sysInfo.sh
  • 将脚本放在工作目录 ~/project 中。

示例

labex:project/ $ bash sysInfo.sh
[INPUT]选择以下选项以显示信息[INPUT]

    1) 当前登录用户
    2) Shell 目录
    3) 主目录
    4) 操作系统名称和版本
    5) 当前工作目录
    6) 登录用户数量
    7) 系统中可用的 Shell
    8) 硬盘信息
    9) CPU 信息
    10) 内存信息
    11) 文件系统信息
    12) 当前正在运行的进程(用户 ID)

1
[OUTPUT]当前登录用户[OUTPUT]
labex
✨ 查看解决方案并练习

总结

完成这个挑战后,你将学会如何使用各种系统信息命令来显示系统的重要信息。你还将获得在 bash 脚本中使用 switch case 语句的经验,从而为用户提供一个可供选择的菜单。这个脚本对于系统管理员或任何想要快速查看各种系统信息而无需手动运行多个命令的人来说都很有用。