Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

linux if statement

Posted on 2013-01-10
7
271 Views
Last Modified: 2013-01-10
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.
0
Comment
Question by:atom_jelly
7 Comments
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 84 total points
ID: 38763160
your question is not clear, please elaborate.
0
 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 250 total points
ID: 38763180
You can have
if ! $(rpm -qa | grep -q release)
then
    echo found
fi

Open in new window

0
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 166 total points
ID: 38763199
releases=$(rpm -qa | grep release)
if $(echo ${releases} | grep release)
then
  echo "releases found: ${releases}
else
  echo "no releases found:
fi;
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 31

Assisted Solution

by:farzanj
farzanj earned 250 total points
ID: 38763217
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
 
LVL 38

Assisted Solution

by:Gerwin Jansen, EE MVE
Gerwin Jansen, EE MVE earned 166 total points
ID: 38763260
(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
 
LVL 31

Accepted Solution

by:
farzanj earned 250 total points
ID: 38763270
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
 

Author Closing Comment

by:atom_jelly
ID: 38763317
Thank you all.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question