写一个Linux shell脚本 用lsb_release识别Linux 系统和版本号自动将系统终端变为中文 假设一切不可能 例如 没有lsb-core 也没有中文字体包等等 考虑各个系统之间的差异 必须支持乌班图18 20 22 刷新变量 中文回答我
#!/bin/bash
获取系统版本号
if [ -f /etc/os-release ]; then source /etc/os-release if [ "$ID" == "ubuntu" ]; then VERSION=$VERSION_ID else VERSION=$(lsb_release -rs) fi elif [ -f /etc/lsb-release ]; then source /etc/lsb-release VERSION=$DISTRIB_RELEASE fi
判断系统是否为中文
if [ "$(locale | grep -oP 'LANG=\K[^_]+')" != "zh_CN" ]; then # 安装中文语言包 if [ "$ID" == "ubuntu" ]; then apt-get update apt-get install -y language-pack-zh-hans else yum update yum -y groupinstall "Chinese Support" fi fi
设置系统语言为中文
export LC_ALL=zh_CN.UTF-8 export LANG=zh_CN.UTF-8
刷新终端变量
if [ "$TERM" == "xterm" ]; then export TERM=xterm-256color fi
echo "系统已设置为中文,版本号为:$VERSION
原文地址: http://www.cveoy.top/t/topic/fPjh 著作权归作者所有。请勿转载和采集!