linux if statement

trying to understand how to put together an if statement that will

first check if the rpm finds any "release"

if not "redhat-release" then output what it found

and echo that and end the if statment

what I have is

if ! rpm -qa | grep "release"



thanks.
atom_jellyAsked:
Who is Participating?
 
farzanjConnect With a Mentor Commented:
As per your requirements, perhaps it should be

release=$(rpm -qa | grep release)
if ! $(echo $releases | grep -iq "redhat-release")
then
  echo "Red Hat release found"
else
  echo "release : $release"
fi
0
 
omarfaridConnect With a Mentor Commented:
your question is not clear, please elaborate.
0
 
farzanjConnect With a Mentor Commented:
You can have
if ! $(rpm -qa | grep -q release)
then
    echo found
fi

Open in new window

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
releases=$(rpm -qa | grep release)
if $(echo ${releases} | grep release)
then
  echo "releases found: ${releases}
else
  echo "no releases found:
fi;
0
 
farzanjConnect With a Mentor Commented:
Let me revise my code

release=$(rpm -qa | grep release)
if ! $(echo $releases | grep -q release)
then
  echo $release
else
  echo "release : $release"
fi

Open in new window

0
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic Advisor Commented:
(a bit to quick in previous post..)

This works:
releases=$(rpm -qa | grep release)
if $(echo ${releases} | grep -q release)
then
  echo "releases found: ${releases}"
else
  echo "no releases found"
fi;

Open in new window

0
 
atom_jellyAuthor Commented:
Thank you all.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.