As you've seen, the PARSE SOURCE keywords can parse information about the operating system. The first word is the name of the operating system. But PARSE SOURCE also returns additional information (ie, more words). The second word is either COMMAND, FUNCTION, or SUBROUTINE, depending on how your script was run (and what your caller expects you to return, if anything). These two words are followed by the complete path specification of the script.

For example, here we display the information about the script's name:

/* Get the full name of the script into the
 * variable "name". Note the two dots before "name".
 * These are very important, as we want to throw away
 * the operating system name, as well as the second
 * word.
 */
PARSE SOURCE . . name

/* Display the information. */
SAY "Full name:" name
SAY "Located on drive:" FILESPEC('D', name)
SAY "In the directory:" FILESPEC('D', name) || FILESPEC('P', name)
Note: The PARSE SOURCE information can vary with different REXX interpreters. Reginald's format is as above. Most modern interpreters follow this format.

Also note that scripts embedded inside of a macro DLL or EXE (ie, created with REXX Programmer Center) do not have a path (drive/directory).

A useful thing you can do with the second word returned by PARSE SOURCE is to discover whether whomever called you expects you to return some value. If the entity that called you requires you to return a value, then the second word will be FUNCTION. In this case, if you do not return a value, then you may cause an error in whomever called you. For example, if your script was called by another script, then not returning a value will cause the SYNTAX condition to be raised in that other script.

/* Get the second word of PARSE SOURCE into the
 * variable "flag". Note the dot before and after "flag".
 */
PARSE SOURCE . flag .

/* Check if we need to return a value. */
IF flag \== "FUNCTION" THEN RETURN

/* We must return a value. Normally, we'd
 * know what we're supposed to return here. Or, we'd
 * try to discover who was calling us, such as checking
 * what our current Environment name is, and hoping this
 * is familiar to us and tells us what we need to return.
 * But let's just return a 0 since that's often used to
 * indicate success.
 */
RETURN 0
Reginald's UNAME() function can also return the name of whomever ran your script.