LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-10-2010, 09:04 AM   #1
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
REXX code executes grep, generates spurious error message


I'm porting my Reginald/Windows REXX programs to Regina/Linux. This requires minor recoding. However, I now realise that large clumps of REXX code may be replaced with small clumps of Linux commands. The result is fewer lines of code and, in some cases, *much* shorter execution time.

My recoded programs exhibit a vexing cosmetic problem. To illustrate with a contrived example which uses a famous Edgar Allen Poe poem:

"grep 'Quoth' < " raven

This works and prints the five lines which contain the word Quoth.


"grep 'Spoke' <" raven

The poem does not contain the word Spoke, so nothing should be printed. However, executing this code from within my Regina REXX program produces this:
11 *-* "grep 'Spoke' <" raven
+++ RC=1 +++

I don't consider this an error. grep searched for a specific character string and printed all that were found (none).

How may I suppress this spurious error message?

Daniel B. Martin
 
Old 05-11-2010, 02:07 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
You can't really stop grep from returning a return code.

Now it's been about 11 years that I last touched REXX,
plus I don't know what your code is meant to achieve,
so can't tell you HOW it's done. What you need to do
is to capture the output of the grep in a variable and
return the result explicitly if there was one.



Cheers,
Tink
 
Old 05-11-2010, 05:45 PM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 719

Rep: Reputation: 72
Hi.

You could write your own script that runs grep and always returns an exit status of zero, then call your script in place of grep.

If you wanted a more complete version, you could have your script return zero if the grep exit code were zero or one, and the actual status if other than either of those ... cheers, makyo

Last edited by makyo; 05-11-2010 at 05:47 PM.
 
Old 05-12-2010, 05:17 AM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 719

Rep: Reputation: 72
Hi.

Here's an example of a script that returns 0 for grep exit status 0,1, "my-grep":
Code:
#!/usr/bin/env bash

# @(#) my-grep	Make grep exit status 1 into 0.

grep "$@"
status=$?

if [ "$status" -gt 1 ]
then
  exit $status
else
  exit 0
fi
So, for a data file "data1":
Code:
foo
bar
baz
the rexx script "s1":
Code:
#!/usr/bin/rexx -

/*

# @(#) s1	Demonstrate results of wrapper script.

*/

say
say ' Hello, world from rexx.'

say
say " Version of rexx:"
"rexx -version"

say
say " Looking for bar."
"grep bar < data1"

say
say " Looking for qux, expect message."
"grep qux < data1"

say
say " Looking for qux, made into 0 by wrapper script, expect no output."
"./my-grep qux < data1"

say
say " Real error results in a message."
"./my-grep a b c"

say
say " At the end."
when run, produces:
Code:
% ./s1

 Hello, world from rexx.

 Version of rexx:
REXX-Regina_3.3 5.00 25 Apr 2004

 Looking for bar.
bar

 Looking for qux, expect message.
    22 *-* "grep qux < data1"
       +++ RC=1 +++

 Looking for qux, made into 0 by wrapper script, expect no output.

 Real error results in a message.
grep: b: No such file or directory
grep: c: No such file or directory
    30 *-* "./my-grep a b c"
       +++ RC=2 +++

 At the end.
The script needs to be a directory in your PATH collection, or run from the current directory as I did in this script with "./my-grep ...".

Best wishes ... cheers, makyo

Last edited by makyo; 05-12-2010 at 05:21 AM.
 
Old 06-07-2010, 09:59 AM   #5
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Original Poster
Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Thank you, Mayko, for your interest. Real-life demands distracted me from pursuing this question until now.

I attempted to run your code without success. Where do I put my-grep? Should it be a subroutine, internal to my Regina Rexx program? If it is to be a separate program, what name should it have?

I made it separate and named it my-grep.rex but that resulted in:
Looking for qux, made into 0 by wrapper script, expect no output.
sh: ./my-grep: not found

Regina couldn't find my-grep.

What should I do next?

Daniel B. Martin
 
Old 06-07-2010, 10:27 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
So long since I used Rexx but isn't the display of non-zero return codes configurable? Ah yes -- TRACE O will do it according to this page.
 
Old 06-07-2010, 10:56 AM   #7
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 719

Rep: Reputation: 72
Hi.

Yes, catkin's post is very useful.

Both trace and TRACE work. That seems to be better from a portability point of view. You can keep my suggestion in mind for a *nix-related suggestion.

Here's a modified version of my test script using trace:
Code:
#!/usr/bin/regina -

/*

# @(#) s3	Demonstrate results of TRACE O, rexx / regina.

*/

say
say ' Hello, world from regina.'

say
say " Version of regina:"
"regina -version"

say
say " Looking for bar."
"grep bar < data1"

trace n
say
say " Looking for qux, expect message, trace n(ormal)."
"grep qux < data1"

trace o
say
say " Looking for qux, trace o(ff)."
"grep qux < data1"

say
say " Looking for qux, 0 by wrapper script, expect no output, trace o."
"./my-grep qux < data1"

TRACE N
say
say " Looking for qux, 0 by wrapper script, expect no output, trace n."
"./my-grep qux < data1"

say
say " Real error results in a message, trace n."
"./my-grep a b c"

say
say " At the end."
producing:
Code:
% ./s3

 Hello, world from regina.

 Version of regina:
REXX-Regina_3.3(MT) 5.00 25 Apr 2004

 Looking for bar.
bar

 Looking for qux, expect message, trace n(ormal).
    23 *-* "grep qux < data1"
       +++ RC=1 +++

 Looking for qux, trace o(ff).

 Looking for qux, 0 by wrapper script, expect no output, trace o.

 Looking for qux, 0 by wrapper script, expect no output, trace n.

 Real error results in a message, trace n.
grep: b: No such file or directory
grep: c: No such file or directory
    41 *-* "./my-grep a b c"
       +++ RC=2 +++

 At the end.
Best wishes ... cheers, makyo
 
Old 06-09-2010, 04:42 PM   #8
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,165

Original Poster
Rep: Reputation: 306Reputation: 306Reputation: 306Reputation: 306
Quote:
Originally Posted by catkin View Post
So long since I used Rexx but isn't the display of non-zero return codes configurable? Ah yes -- TRACE O will do it according to this page.
Perfect! Thank you! SOLVED!

Daniel B. Martin
 
  


Reply

Tags
error, message


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
evolution generates an error: relay denied when it tries to retrieve an email message rcmonroig Linux - Server 3 03-14-2010 11:14 AM
What version of syslog generates "last message received x times" messages? invalid entry Red Hat 2 11-18-2009 09:39 AM
Getting Spurious error on Linux 2.6.20 vipulp Linux - Embedded & Single-board computer 2 12-07-2007 04:20 AM
LXer: Rexx and what it means for AIX LXer Syndicated Linux News 0 03-27-2007 10:16 PM
"permission denied" error when cron job executes jillu Linux - Newbie 11 11-02-2004 02:19 PM


All times are GMT -5. The time now is 08:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration