我对 Bash 脚本相当陌生,目前正在根据用户的操作系统创建一个安装程序来使用 Docker-Compose 安装 Docker 客户端。该脚本不打算在每个操作系统上运行,其范围仅适用于 Ubuntu 16.04、18.04、CentOS 7 和 8。
我编写了以下代码来验证用户的操作系统并开始安装过程(目前,我正在尝试使其适用于 Ubuntu 18.04):
################
### Check OS ###
################
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
RESULT="$OS $VER"
printf -v $RESULT "Ubuntu 18.04"
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# …Run Code Online (Sandbox Code Playgroud)