Sample Header Ad - 728x90

Why won't || work in a shell script?

-3 votes
2 answers
166 views
# Detect Operating System
function dist-check() {
  # shellcheck disable=SC1090
  if [ -e /etc/os-release ]; then
    # shellcheck disable=SC1091
    source /etc/os-release
    DISTRO=$ID
    # shellcheck disable=SC2034
    DISTRO_VERSION=$VERSION_ID
  fi
}

# Check Operating System
dist-check

# Pre-Checks
function installing-system-requirements() {
  # shellcheck disable=SC2233,SC2050
  if ([ "$DISTRO" == "ubuntu" ] || [ "$DISTRO" == "debian" ] || [ "DISTRO" == "raspbian" ]); then
    apt-get update && apt-get install iptables curl coreutils bc jq sed e2fsprogs -y
  fi
  # shellcheck disable=SC2233,SC2050
  if ([ "$DISTRO" == "fedora" ] || [ "$DISTRO" == "centos" ] || [ "DISTRO" == "rhel" ]); then
    yum update -y && yum install epel-release iptables curl coreutils bc jq sed e2fsprogs -y
  fi
  if [ "$DISTRO" == "arch" ]; then
    pacman -Syu --noconfirm iptables curl bc jq sed
  fi
}

# Run the function and check for requirements
installing-system-requirements
Why wont this run? I am using || to separate the distros but its still not working.
Asked by Prajwal Koirala (15 rep)
Oct 31, 2020, 01:52 AM
Last activity: Oct 31, 2020, 08:12 AM