LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-14-2020, 02:14 PM   #1
witchkinkofangmar
Member
 
Registered: May 2019
Posts: 83

Rep: Reputation: Disabled
CentOS8 if condition being ignored


Trying to differentiate between CentOS7 and CentOS8 and the CentOS8 condition is being skipped and I'm not sure why.

Code:
release=$(cat /etc/redhat-release | awk '{print $1,$2}')
release8="cut -c22 /etc/redhat-release"

if [[ -d "$sepDir" ]]; then
  echo "$(tput setaf 1)$(tput setab 7)Symantec Endpoint Protection is already installed.$(tput sgr 0)"
elif [[ ! -d "$sepDir" && $release == 'Red Hat' ]]; then
  echo "$(tput setaf 1)$(tput setab 7)RHEL Install.$(tput sgr 0)"
  sepInstallRHEL
elif [[ ! -d "$sepDir" && "$release8" == '8' ]]; then
  echo "CentOS 8 install"
  sepInstallCentOS8
elif [[ ! -d "$sepDir" && $release == 'CentOS Linux' || $release == 'CentOS release' ]]; then
  echo "$(tput setaf 1)$(tput setab 7)CentOS Install.$(tput sgr 0)"
  sepInstallCentOS
else
  echo "An error has occurred. Please contact your Systems Administrator."
fi
 
Old 08-14-2020, 02:50 PM   #2
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,601

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

You're setting release8 to the string "cut -c22 /etc/redhat-release" instead of evaluating it like you do for the variable one line previous.

Using Bash's -x mode should make this obvious when you run the script.

Also, grabbing the 22nd character of every line doesn't seem like a great way to identify version.

Do those OSes not use /etc/os-release, where you can simply grab the value of the VERSION_ID line, e.g.
Code:
grep -oP '(?<=VERSION_ID=")\d+' /etc/os-release

Last edited by boughtonp; 08-14-2020 at 03:01 PM.
 
1 members found this post helpful.
  


Reply

Tags
bash script, centos7, centos8, condition-variables



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Alternative to /etc/hosts/allow on CentOS8 elliot01 Linux - Security 13 01-11-2021 10:12 AM
Centos8 Installer can't detect disk santhosh94 Linux - Newbie 5 11-14-2019 07:42 AM
Centos8 Installer can't detect disk santhosh94 Linux - Server 2 11-12-2019 02:47 PM
check Negative egrep condition in an if condition novicunix Programming 5 02-02-2013 12:52 AM
using OR condition in if condition Fond_of_Opensource Linux - Newbie 2 10-20-2006 12:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration