小编Dav*_*has的帖子

Bash 脚本:如果变量等于字符串

我对 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)

linux bash installation scripting if-statement

3
推荐指数
1
解决办法
4646
查看次数

标签 统计

bash ×1

if-statement ×1

installation ×1

linux ×1

scripting ×1