Leveraging PARSE from Open Object Rexx in Bash

Some time ago, I was lamenting that Bash did not have something comparable to PARSE found in Rexx / Open Object Rexx. Shortly I received a reply from Dallas Legan that he had built a tool capable of exposing the power of PARSE and allow it to be used within Bash scripts. That concept totally rocks! That tool may be found here:

"A Simple, General Command Line Filter In REXX"

The way I put it to use is for extracting and acting upon the final "return code" of an executed program which is itself creating a log file and included on the last line the program's exit code.

Log file example:

adding: srv/www/sites/domain.com/cgi-bin/program/file1.dat (deflated 78%)
adding: srv/www/sites/domain.com/cgi-bin/program/file2.dat (deflated 82%)
Finished Backing Up!

Purging Old Backups...
Finished Purging!
backup.sh complete! RC=0

Bash script usage example:

RC=`/usr/bin/tail -n 1 /srv/www/reports/$DATE.backup.sh.log | /srv/www/bin/parse.rex ". 'RC=' US ."`
[ "$RC" != "0" ] && /usr/bin/tail /srv/www/reports/$DATE.backup.sh.log | /usr/bin/mailx -s "$DATE.backup.sh.log" reportaddy

So by processing the last line of the log file with Rexx's PARSE, I can cleanly extract just the numeric value which RC= states as the exit of that script. The bonus is that I can use PARSE's syntax which I am used to within Bash!

One minor problem crept into this pretty picture. When ooRexx 4.0.1 was released, it had a bug that prevented the PARSE script from working properly. I arrived at a slight modification to the script that gets around the bug in ooRexx 4.0.1. You may download / apply my patch file here: