Bash script conditional not working
by witchkinkofangmar from LinuxQuestions.org on (#58PQQ)
I have two functions, one for CentOS7 and one for CentOS8. My code only runs the CentOS7 function even if it's on a CentOS8 machine. I'm not sure why:
Code:release=$(cat /etc/redhat-release | awk '{print $1,$2}')
release8=$(cut -c22 /etc/redhat-release)
if [[ $release == 'CentOS Linux' || $release == 'CentOS release' && $release8 == '7' ]]; then
echo "CentOS Install"
secureInstall
elif [[ $release == 'CentOS Linux' || $release == 'CentOS release' && $release8 == '8' ]]; then
echo "CentOS 8 Install"
secureInstall8
elif [[ $release == 'Red Hat' ]]; then
echo "RHEL Install"
secureInstall
else
echo "Unsupported OS. Contact Support"
fi


Code:release=$(cat /etc/redhat-release | awk '{print $1,$2}')
release8=$(cut -c22 /etc/redhat-release)
if [[ $release == 'CentOS Linux' || $release == 'CentOS release' && $release8 == '7' ]]; then
echo "CentOS Install"
secureInstall
elif [[ $release == 'CentOS Linux' || $release == 'CentOS release' && $release8 == '8' ]]; then
echo "CentOS 8 Install"
secureInstall8
elif [[ $release == 'Red Hat' ]]; then
echo "RHEL Install"
secureInstall
else
echo "Unsupported OS. Contact Support"
fi