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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-10-2010, 08:04 AM
|
#1
|
|
Member
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 765
Rep: 
|
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
|
|
|
|
05-11-2010, 01:07 PM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,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
|
|
|
|
05-11-2010, 04:45 PM
|
#3
|
|
Member
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 713
Rep:
|
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 04:47 PM.
|
|
|
|
05-12-2010, 04:17 AM
|
#4
|
|
Member
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 713
Rep:
|
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":
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 04:21 AM.
|
|
|
|
06-07-2010, 08:59 AM
|
#5
|
|
Member
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 765
Original Poster
Rep: 
|
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
|
|
|
|
06-07-2010, 09:27 AM
|
#6
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
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.
|
|
|
|
06-07-2010, 09:56 AM
|
#7
|
|
Member
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 713
Rep:
|
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
|
|
|
|
06-09-2010, 03:42 PM
|
#8
|
|
Member
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 765
Original Poster
Rep: 
|
Quote:
Originally Posted by catkin
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
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:15 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|