#!/bin/bash# 预设系统信息
KERNEL_NAME="Linux"
NODENAME="localhost.localdomain"
KERNEL_RELEASE="3.10.0-957.el7.x86_64"
KERNEL_VERSION="#1 SMP Thu Nov 8 23:39:32 UTC 2018"
MACHINE="x86_64"
PROCESSOR="x86_64"
HARDWARE_PLATFORM="x86_64"
OPERATING_SYSTEM="GNU/Linux"# 处理命令行参数
while [[ $# -gt 0 ]]; docase "$1" in-a|--all)echo "$KERNEL_NAME $NODENAME $KERNEL_RELEASE $KERNEL_VERSION $MACHINE $PROCESSOR $HARDWARE_PLATFORM $OPERATING_SYSTEM"exit 0;;-s|--kernel-name)echo "$KERNEL_NAME"exit 0;;-n|--nodename)echo "$NODENAME"exit 0;;-r|--kernel-release)echo "$KERNEL_RELEASE"exit 0;;-v|--kernel-version)echo "$KERNEL_VERSION"exit 0;;-m|--machine)echo "$MACHINE"exit 0;;-p|--processor)echo "$PROCESSOR"exit 0;;-i|--hardware-platform)echo "$HARDWARE_PLATFORM"exit 0;;-o|--operating-system)echo "$OPERATING_SYSTEM"exit 0;;--help)echo "Usage: uname [OPTION]..."echo "Print certain system information. With no OPTION, same as -s."echo " -a, --all print all information, in the following order,"echo " except omit -p and -i if unknown:"echo " -s, --kernel-name print the kernel name"echo " -n, --nodename print the network node hostname"echo " -r, --kernel-release print the kernel release"echo " -v, --kernel-version print the kernel version"echo " -m, --machine print the machine hardware name"echo " -p, --processor print the processor type or \"unknown\""echo " -i, --hardware-platform print the hardware platform or \"unknown\""echo " -o, --operating-system print the operating system"echo " --help display this help and exit"echo " --version output version information and exit"echo "GNU coreutils online help: <http://www.gnu.org/software/coreutils/>"echo "For complete documentation, run: info coreutils 'uname invocation'"exit 0;;--version)echo "uname (GNU coreutils) 8.22"echo "Copyright (C) 2013 Free Software Foundation, Inc."echo "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>."echo "This is free software: you are free to change and redistribute it."echo "There is NO WARRANTY, to the extent permitted by law."echo "Written by David MacKenzie."exit 0;;*)echo "uname: invalid option -- '$1'"echo "Try 'uname --help' for more information."exit 1;;esacshift
done# 没有参数时,默认输出内核名称
echo "$KERNEL_NAME"