Environment variables: Difference between revisions

Content deleted Content added
Peak (talk | contribs)
jq
m {{Out}} / moved Category to top
Line 1:
{{task|Programming environment operations}}[[Category: Environment variables]] [[Category:Initialization]]
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have an environment other than regular global variables. -->
Show how to get one of your process's [[wp:Environment variable|environment variables]]. The available variables vary by system; some of the common ones available on Unix include PATH, HOME, USER.
{{omit from|M4}}
{{omit from|Unlambda|Does not provide access to environment variables.}}
{{task|Programming environment operations}}
Show how to get one of your process's [[wp:Environment variable|environment variables]].
Show how to get one of your process's [[wp:Environment variable|environment variables]]. The available variables vary by system; some of the common ones available on Unix include PATH, HOME, USER.
 
=={{header|Ada}}==
Line 268 ⟶ 273:
fmt.Println(os.Getenv("SHELL"))
}</lang>
{{out}}
Output:
<pre>
/bin/bash
</pre>
;Alternatively:
Library function os.Environ returns all environment variables. You're on your own then to parse out the one you want. Example:
You're on your own then to parse out the one you want.
Example:
<lang go>package main
 
Line 293 ⟶ 300:
fmt.Println(s, "not found")
}</lang>
{{out}}
Output:
<pre>
SHELL has value /bin/bash
Line 372 ⟶ 379:
stdoutnl(getenv('USER'))
stdoutnl(getenv('WHAT'))</lang>
{{out}}
Output:
<pre>/Users/rosetta
/opt/local/bin:/opt/local/sbin:/usr/local/bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
rosetta
 
</pre>
 
Line 424 ⟶ 430:
}
}</lang>
{{out}}
Output:
<pre>llGetTimestamp()=2012-07-18T01:26:12.133137Z
llGetEnergy()=1.230000
Line 552 ⟶ 558:
return
</lang>
{{out}}
'''Output:'''
<pre>
---- Environment "CLASSPATH" ---------------------------------------------------
Line 764 ⟶ 770:
print "Default Dir is : ";DefaultDir$</lang>
<pre>
{{out}}
Output:
User Info is : Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11
Platform is : win32
Line 774 ⟶ 780:
 
=={{header|Scala}}==
[[Category:Scala Implementations]]
{{libheader|Scala}}
<lang scala>object Environment_variables extends App {
Line 866 ⟶ 871:
Now child processes launched by the shell will have an environment variable called <code>VAR</code>.
 
The Unix command "env" will print out all of the environment variables as key=value pairs on standard output.
as key=value pairs on standard output.
 
=={{header|Ursala}}==
Line 875 ⟶ 881:
 
showenv = <.file$[contents: --<''>]>+ %smP+ ~&n-={'TERM','SHELL','X11BROWSER'}*~+ ~environs</lang>
The rest of this application searches for the three variables named and displays them on standard output.
and displays them on standard output.
Here is a bash session.
 
{{out|Here is a bash session.}}
<pre>
$ showenv
Line 925 ⟶ 933:
]</lang>
 
{{out}}
Output:
<pre>
PATH=\masm6;C:\;C:\CXPL;C:\UTIL;C:\DOS;C:\BORLANDC\BIN
Line 934 ⟶ 942:
/home/craigd
System.getenv() //--> Dictionary of all env vars</lang>
 
{{omit from|TI-83 BASIC}} {{omit from|TI-89 BASIC}} <!-- Does not have an environment other than regular global variables. -->
{{omit from|M4}}
{{omit from|Unlambda|Does not provide access to environment variables.}}