rexx-things/projects/oorexx/envvars.rex

53 lines
1.3 KiB
Rexx
Executable File

#!/usr/bin/env rexx
parse source os .
if os~startsWith("Win") then command='set'
else command='env | sort -f'
say "operating system: "os', command was: "'command'"'
Say "---"
call env_with_array
Say "---"
call env_with_stem
Exit
env_with_array:
Say "Getting Environment Vars Using Array:"
vars=.array~new
address system command with output using (vars)
len=vars~items~length
say "Number of env vars: "||vars~items
if rc=0 then
do counter i var over vars
select
when var~startsWith("PWD") then parse var var . "=" pwd
when var~startsWith("HOME") then parse var var . "=" home
when var~startsWith("SHELL") then parse var var . "=" shell
otherwise nop
end /* select */
end
say home
say pwd
say shell
Return
env_with_stem:
Say "Getting Environment Vars Using STEM: "
address system command with output stem env.
say "Number of env vars: "||env.0
Do i = 1 to env.0
select
when env.i~startsWith("PWD") then parse var env.i . "=" pwd
when env.i~startsWith("HOME") then parse var env.i . "=" home
when env.i~startsWith("SHELL") then parse var env.i . "=" shell
otherwise nop
end/* select*/
End
say home
say pwd
say shell
Return