Solved

linux if statement

Posted on 2013-01-10
7
268 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 37

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 37

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
High Bandwidth Usage 6 56
Choosing CentOS 16 81
ROBOFTP UNZIP 1 45
SIP / Streaming - real time communications testing 8 51
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

773 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