parsing error in if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting parsing error in if statement
# 1  
Old 09-24-2007
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  
Old 09-24-2007
Quote:
Originally Posted by rakeshou
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  
Old 09-25-2007
Quote:
Originally Posted by porter
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 11:53 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a PATH statement

I have a script that will be placing a trigger file for other applications. The user-inputted path is similar to: "/data/region/NorthAm/Project HAV 8H" The project path will not change throughout the script. However, pwd changes as the scanning continues in the script. I need to truncate... (3 Replies)
Discussion started by: leepet
3 Replies

2. Shell Programming and Scripting

Error in if statement

I am working on script for stale nfs. the file consists of cat data01stale.log - - - - /abcd/backup - - - - /abcd/data Script (16 Replies)
Discussion started by: nareshkumar522
16 Replies

3. AIX

parsing error when I run RSYNC

This is what I get when I run the RSYNC command. I just created brand new ssh2 rsa keys. warning: /come/out/and/play/.ssh2/id_rsa_2048_a: 4: parsing line failed. warning: /come/out/and/play/.ssh2/id_rsa_2048_a: 5: parsing line failed. warning: " " " " " " " " ... (3 Replies)
Discussion started by: tfort73
3 Replies

4. UNIX for Dummies Questions & Answers

error in if statement

Hi, This is my script to catch any oracle errors. In this, the $sqlerr returns ORA-01017: invalid username/password; logon denied when i specify wrong username/password the if condition is failing. how can i resolve the issue. the if statement gives error sqloutput=`sqlplus -s -L... (1 Reply)
Discussion started by: Swapna173
1 Replies

5. Shell Programming and Scripting

Sed parsing error

I'm having a problem with a sed script. A programmer needs to change columns 942,943,944 to blank spaces only where it has the number 999 in every line. I didn't have a copy of the data file to test with originally so made my own up with a bunch of x's and put 999 in columns 5-7. The sed... (1 Reply)
Discussion started by: gravy26
1 Replies

6. Shell Programming and Scripting

Error in IF statement

HI i am getting error while executing the given statement for filename in `cat a/file.lst` do if then echo "Exit Code Description :File $filename - is missing in Input Directory" >a.log exit else count1=`awk 'END {print NR}' $filename` echo "$count1">>a.log count2=`awk 'END {print... (4 Replies)
Discussion started by: ravi214u
4 Replies

7. Linux

error in if statement

Hi , I am getting an error when I run the script for checking word "view" in a file . I am using if statement. like this if then VW_VAR=` cat $TN.${ecmdate}.sql1 | grep -i view | awk '{print $3}' | cut -d '.' -f2 ` echo " VW_$VW_VAR " sed -e... (16 Replies)
Discussion started by: capri_drm
16 Replies

8. Shell Programming and Scripting

Error with if statement..Please help

:b:hi, I have a script as given below: pr_det="1" if then awk ' BEGIN {printf("%23s","session")}' >> report.txt awk ' BEGIN {printf "\n"} ' >> report.txt else awk ' BEGIN {printf("%55s","file_dsc")} ' >> report.txt awk ' BEGIN {printf("%101s","no_recs")} '... (1 Reply)
Discussion started by: jisha
1 Replies

9. Shell Programming and Scripting

(sed) parsing insert statement column that crosses multiple lines

I have a file with a set of insert statements some of which have a single column value that crosses multiple lines causing the statement to fail in sql*plue. Can someone help me with a sed script to replace the new lines with chr(10)? here is an example: insert into mytable(id, field1, field2)... (3 Replies)
Discussion started by: jjordan
3 Replies

10. UNIX for Advanced & Expert Users

xml parsing error in perl

******************PERL VERSION************************ This is perl, v5.8.1 built for i386-linux-thread-multi ERROR!!!!---Undefined subroutine &main::start called at /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/XML/Parser/Expat.pm line 469. *********************PERL... (1 Reply)
Discussion started by: bishweshwar
1 Replies
Login or Register to Ask a Question