Jump to content

Environment variables: Difference between revisions

(→‎{{header|UNIX Shell}}: These things are Unix standard, not bash-specific. The env utility does not print to "the screen". Mention the export command.)
Line 489:
The <code>env</code> global array maps environmental variable names to their values:
<lang tcl>$env(HOME)</lang>
 
=={{header|TXR}}==
 
{{works with|TXR|"git head"}}
 
TXR can treat the environment vector as text stream:
 
<lang txr>@(next :env)
@(collect)
@VAR=@VAL
@(end)</lang>
 
A recently added <code>gather</code> directive is useful for extracting multiple items of data from an unordered stream of this kind (not only the environment vector):
 
<lang txr>@(next :env)
@(gather)
HOME=@home
USER=@user
PATH=@path
@(end)</lang>
 
What if some of the variables might not exist? Gather has some discipline for that. The following means that three variables are required (the gather construct fails if they are not found), but <code>shell</code> is optional with a default value of <code>/bin/sh</code> if it is not extracted from the data:
 
<lang txr>@(next :env)
@(gather :vars (home user path (shell "/bin/sh")))
HOME=@home
USER=@user
PATH=@path
SHELL=@shell
@(end)</lang>
 
On POSIX, environment variables, which are extracted using <code>extern char **environ</code> are assumed to contain UTF-8. On Windows, the <code>GetEnvironmentStringsW</code> function is used to obtain the environment vector as wide character data.
 
=={{header|UNIX Shell}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.