Contributed by: Darin McBride
Ever wanted a rexx script that was both a function for other code, and a command that you could use at the command prompt? Some sneaky code, and you can have it. This example shows the "GetEnv" idea: when it's a function, it returns the value, but when it's a command, it prints the value, and gives a meaningful (0/non-0) return code.
/*
* GetEnv2
*
* Parameters:
* OS/2 environment variable to look up.
*/
parse source . c .
parse arg var
rc = value(var,, 'OS2ENVIRONMENT')
select
when c = 'COMMAND' then
do
if rc = '' then
do
say '"'var'" is not in the environment'
rc = 1
end
else
do
say rc;
rc = 0;
end
end
otherwise
nop
end
return rc