Register
It is currently Mon Jul 28, 2014 10:26 am

Need to rid of some output


All times are UTC - 6 hours


Post new topic Reply to topic  [ 6 posts ] 
Author Message
 PostPosted: Thu Dec 11, 2008 2:08 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hi everyone,

How do I get rid of the output generated by the grep '^ELF' statement?

Code:
#!/bin/bash
if file -b $i | grep "^ELF"; then 
   echo "$i is a library";
else    
   echo "not a library";
fi


Top
 Profile  
 PostPosted: Fri Dec 12, 2008 3:07 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
Here are a couple of ways.
Firstly recent versions of grep have a '-q' switch which suppresses output, perfect for if statements.

Code:
if file -b $i | grep -q "^ELF"


or just redirect the output

Code:
if file -b $i | grep "^ELF" >/dev/null


Top
 Profile  
 PostPosted: Fri Dec 12, 2008 7:28 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
or do it the long way around :P
Code:
file -b $i | grep "^ELF" > /dev/null
if [ $? -eq 0 ]; then

fi


Dunno how well if likes when you need to redirect stderr at the same time, i've done this way sometimes for reasons I cannot remember now :P

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Fri Dec 12, 2008 11:02 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
neither worked X\


Top
 Profile  
 PostPosted: Fri Dec 12, 2008 9:31 pm   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Code:
file -b $i | grep "^ELF" 2>&1 /dev/null
if [ $? -eq 0 ]; then

fi


That should do the trick, if it's stderr that is... i'm quite drunk atm so i donot guarantee that quality of this :P

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Sat Dec 13, 2008 7:53 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
godammit you're always drunk :lol:


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP