写一个Linux shell脚本 用lsb_release识别Linux 系统和版本号自动将系统终端变为中文 假设一切不可能 例如 没有lsb-core 也没有中文字体包等等 考虑各个系统之间的差异 必须支持乌班图18 20 22 刷新变量
#!/bin/bash
Check if lsb_release command exists
if ! command -v lsb_release >/dev/null 2>&1; then echo "lsb_release command not found. Exiting." exit 1 fi
Get Linux distribution and version
distro=$(lsb_release -si) version=$(lsb_release -sr)
Convert to lowercase for easier comparison
distro=$(echo "$distro" | tr '[:upper:]' '[:lower:]')
Check if system is Ubuntu and version is supported
if [[ "$distro" == "ubuntu" && ( "$version" == "18.04" || "$version" == "20.04" || "$version" == "22.04" ) ]]; then
Check if language-pack-zh-hans package is installed
if dpkg -s language-pack-zh-hans >/dev/null 2>&1; then # Set terminal language to Chinese export LC_ALL=zh_CN.UTF-8 export LANG=zh_CN.UTF-8 echo "Terminal language set to Chinese." else echo "language-pack-zh-hans package not found. Please install it and try again." exit 1 fi else echo "Unsupported Linux distribution or version. Exiting." exit 1 fi
Refresh terminal for changes to take effect
source ~/.bashr
原文地址: http://www.cveoy.top/t/topic/fPje 著作权归作者所有。请勿转载和采集!