#!/bin/bash

判断Linux系统类型和版本号

if [ -f /etc/lsb-release ]; then OS=$(grep "DISTRIB_ID" /etc/lsb-release | awk -F= '{print $2}') VERSION=$(grep "DISTRIB_RELEASE" /etc/lsb-release | awk -F= '{print $2}') elif [ -f /etc/os-release ]; then OS=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}') VERSION=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"') else echo "Unrecognized Linux distribution" exit 1 fi

判断是否支持中文

if [[ $OS == "ubuntu" && ($VERSION == "18.04" || $VERSION == "20.04" || $VERSION == "22.04") ]]; then export LANG=zh_CN.UTF-8 elif [[ $OS == "cos" && ($VERSION == "7" || $VERSION == "6") ]]; then export LANG=zh_CN.utf8 else echo "This Linux distribution does not support Chinese" exit 1 fi

将终端设置为中文

export LC_ALL=zh_CN.UTF-8

echo "The terminal has been set to Chinese.

写一个Linux shell脚本 识别Linux 系统和版本号自动将系统终端变为中文 必须支持乌班图18 20 22 cos 7 6

原文地址: http://www.cveoy.top/t/topic/fPiB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录