The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
error in if statement capri_drm Linux 16 05-14-2008 02:00 PM
Error with if statement..Please help jisha Shell Programming and Scripting 1 01-16-2008 07:13 AM
(sed) parsing insert statement column that crosses multiple lines jjordan Shell Programming and Scripting 3 10-09-2007 12:23 AM
xml parsing error in perl bishweshwar UNIX for Advanced & Expert Users 1 05-30-2007 10:59 PM
tar error statement legato UNIX for Dummies Questions & Answers 3 03-29-2005 09:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-24-2007
rakeshou rakeshou is offline
Registered User
  
 

Join Date: May 2007
Posts: 75
parsing error in if statement

hello,

I am trying to parse an error returned by a command inside the if statement but it is just displays the full error instead and then stops.

Code:
if [ `pkginfo xxx | grep "was not found"` ]; then
echo "no such package"
else
echo "similar version found will use pkgrm"
fi
the above code just displays

Quote:
ERROR: ERROR: information for "xxx" was not found
please let me know how can I parse the error message returned by a command inside the if statement.

Thanks
  #2 (permalink)  
Old 09-24-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by rakeshou View Post
hello,

I am trying to parse an error returned by a command inside the if statement but it is just displays the full error instead and then stops.


the above code just displays



please let me know how can I parse the error message returned by a command inside the if statement.

Thanks
Your back quotes just turn the output of the command into a string.

Try

Code:
pkginfo xxx | grep "was not found"

if test "$?" = "0" ; then
echo "no such package"
else
echo "similar version found will use pkgrm"
fi
  #3 (permalink)  
Old 09-25-2007
kahuna's Avatar
kahuna kahuna is offline
Registered User
  
 

Join Date: Apr 2007
Posts: 149
Quote:
Originally Posted by porter View Post
Code:
pkginfo xxx | grep "was not found"
A minor correction. I think part of the problem is that the message is going to stderr and not stdout. It should be

Code:
pkginfo xxx 2>&1 | grep "was not found"

Last edited by kahuna; 09-25-2007 at 10:53 AM..
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0