shell 如何为每个Linux发行版给予不同的输出

t2a7ltrp  于 2022-11-16  发布在  Shell
关注(0)|答案(1)|浏览(136)

我想检查不同的发行版并使用不同的输出,例如,如果它检查并检测到Debian输出为“systemctl reboot -i”,如果它检测到kali,它将更改为“reboot”
我的问题是无法检测操作系统并为每个发行版给予必要的输出,例如,debian 11,Ubuntu,kali和arch的系统命令的微小差异。
我试过使用一个if语句,但一直无法让它工作,可能是因为我缺乏经验。所以,如果任何一个有一个解决方案,请帮助我
full code

#!/bin/bash

RED="\e[31m"
GREEN="\e[32m"
YELOW="\e[33m"  
BLUE="\e[34m"
ENDCOLOR="\e[0m";
echo 
echo 
echo _█████╗_██╗___██╗████████╗_██████╗_███╗___███╗_█████╗_████████╗_██████╗_██████╗ 
echo ██╔══██╗██║___██║╚══██╔══╝██╔═══██╗████╗_████║██╔══██╗╚══██╔══╝██╔═══██╗██╔══██╗
echo ███████║██║___██║___██║___██║___██║██╔████╔██║███████║___██║___██║___██║██████╔╝
echo ██╔══██║██║___██║___██║___██║___██║██║╚██╔╝██║██╔══██║___██║___██║___██║██╔══██╗
echo ██║__██║╚██████╔╝___██║___╚██████╔╝██║_╚═╝_██║██║__██║___██║___╚██████╔╝██║__██║
echo ╚═╝__╚═╝ ╚═════╝____╚═╝____╚═════╝ ╚═╝_____╚═╝╚═╝__╚═╝___╚═╝____╚═════╝_╚═╝__╚═╝
echo 
uptime
who
echo
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
    echo -e "${RED}!!! run as root !!!${ENDCOLOR}"
    echo -e "${RED} or a user with the permisions ${ENDCOLOR}"
    sleep 5
fi
echo
echo
echo -e compleate system setup "${YELOW}[systemsetup]${ENDCOLOR}"
echo -e update "${YELOW}[update]${ENDCOLOR}"
echo -e install Osint tools "${YELOW}[1]${ENDCOLOR}"
echo -e install Exploit tools "${YELOW}[2]${ENDCOLOR}"
echo -e install Wireles tools "${YELOW}[3]${ENDCOLOR}"
echo -e install vulnerability detection tools "${YELOW}[4]${ENDCOLOR}"
echo -e test network "${YELOW}[network]${ENDCOLOR}"
echo -e show options "${YELOW}[op]${ENDCOLOR}"
echo -e show version "${YELOW}[v]${ENDCOLOR}"
echo 
while true; do
read -p "how do you want to proceed? " yn

case $yn in 

# simple uptions output

    system ) echo ;
             echo system tools ;
             echo ;
             echo -e show system info "${YELOW}[sinfo]${ENDCOLOR}";
             echo ;
             echo -e create user "${YELOW}[newuser]${ENDCOLOR}";
             echo -e remuve user "${YELOW}[remuveuser]${ENDCOLOR}";
             echo ;;
fumotvh3

fumotvh31#

我相信/etc/os-release文件包含了你需要的所有信息。你可以catgrep,...来获取所有相关信息。

相关问题