Page 1 of 1

Parsing command-line argumnts in a REXX script

#1 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5322
  • View blog
  • Posts: 27,232
  • Joined: 10-May 07

Posted 10 May 2008 - 11:43 PM

Parsing command-line argumnts in a REXX script

A very useful ability in almost any programming language is to that of passing in command-line arguments.

The usage syntax for this in REXX scripting is
Parse Argument1 Argument2 Argument3 .



The command Parse, will parse in anything that was passed in when the script was called, following the parse template.

/**/
Parse Arg Cust sDate .

ActiveFlag	= '\settle\bin\active.flg'
sDate		= Date('S')

/* Main (Start) */
Select
   When Cust = '' | sDate = '' then Do
	  Say ''
	  Say 'Usage: Settle [Cust] [sdate]'
	  Say ''
	  Say 'Options:'
	  Say '	cust			customer 3 digit code'					/* Display usage message */
	  Say '	sdate			settle date [mmddyy]'
	  Say ''
	  Exit;
   End /* Do */



In our exmaple here, we are expecting the user to provide us with two arguments. The customer number & the date. We check the value of the arguments passed in, & in the event that they are empty, we act accordingly by prompting the user to use the command correctly.

You'll also notice the period the follows the expected arguments. This will absorbe anything unexpected that might be remaining on the command line.


In fact, one of the most powerful features of REXX is its ability to parse text values. So keep in mind that Parse can be used for more than just reading in command-line arguments.
Here is another example of the parse command within the script itself.
/**/
parse value 'Show another example' with word1 word2 word3
  
  say "'"word1"'"
  say "'"word2"'"
  say "'"word3"'"



The output would be:

Quote

'Show'
'another'
'example'


Is This A Good Question/Topic? 1
  • +

Page 1 of 1