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 |
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 |
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 |
Hi.
Here's an example of a script that returns 0 for grep exit status 0,1, "my-grep": Code:
#!/usr/bin/env bash Code:
foo Code:
#!/usr/bin/rexx - Code:
% ./s1 Best wishes ... cheers, makyo |
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 |
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.
|
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 - Code:
% ./s3 |
Quote:
Daniel B. Martin |
All times are GMT -5. The time now is 06:44 AM. |