Environment variables: Difference between revisions

m (syntax highlighting fixup automation)
 
(7 intermediate revisions by 7 users not shown)
Line 342:
=={{header|Emacs Lisp}}==
<syntaxhighlight lang="lisp">(getenv "HOME")</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun showVariable = <text variable|writeLine(variable + ": '" + Runtime.get(variable) + "'")
showVariable("SystemDrive")
showVariable("USERNAME")
# we can get the environment variables as a map
Map variables = Runtime.variables()
writeLine(variables["TEMP"])
</syntaxhighlight>
{{Out}}
<pre>
SystemDrive: 'C:'
USERNAME: 'XXXYYY'
C:\Users\xxxyyy\AppData\Local\Temp
</pre>
 
=={{header|Erlang}}==
Line 409 ⟶ 425:
println( $home )
println( $user )</syntaxhighlight>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
NSLog(@"%@",fn NSUserName)
NSLog(@"%@",fn NSFullUserName)
NSLog(@"%@",fn NSHomeDirectory)
NSLog(@"%@",fn NSTemporaryDirectory)
 
HandleEvents
</syntaxhighlight>
 
=={{header|Go}}==
Line 554 ⟶ 582:
writeln "USER: ", _env["USER"]</syntaxhighlight>
 
{{works with|langur|0.9}}
We could also the short-hand form of indexing by string. This is limited to code points used for tokens and does not allow for spaces, nor an index alternate.
<syntaxhighlight lang="langur">writeln "HOME: ", _env'HOME
Line 891 ⟶ 918:
ExpandEnvStrings $1 "%USERPROFILE%" ; Retrieve the user's profile location and place it in builtin register 1.
ExpandEnvStrings $2 "%USERNAME%" ; Retrieve the user's account name and place it in builtin register 2.</syntaxhighlight>
 
=={{header|Nu}}==
<syntaxhighlight lang="nu">
$env.HOME
</syntaxhighlight>
 
=={{header|Objective-C}}==
Line 938 ⟶ 970:
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">getenv</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"PATH"</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">/# Rosetta Code problem: http://rosettacode.org/wiki/Environment_variables
by Galileo, 10/2022 #/
 
def getenv
" > output.txt" chain cmd if "Error!" else "output.txt" "r" fopen dup fgets swap fclose endif
enddef
 
"path" getenv print</syntaxhighlight>
 
=={{header|PHP}}==
Line 1,134 ⟶ 1,176:
<syntaxhighlight lang="slate">Environment variables at: 'PATH'.
"==> '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games'"</syntaxhighlight>
 
=={{header|Slope}}==
<syntaxhighlight lang="slope">(env "HOME")</syntaxhighlight>
 
=={{header|Smalltalk}}==
Line 1,263 ⟶ 1,308:
'X11BROWSER': '/usr/bin/firefox'></pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">// Environment variables in V
// v run environment_variables.v
module main
Line 1,292 ⟶ 1,337:
 
However, if Wren is embedded in (say) a suitable Go program, then we can ask the latter to obtain it for us.
<syntaxhighlight lang="ecmascriptwren">/* environment_variablesEnvironment_variables.wren */
class Environ {
foreign static variable(name)
Line 1,301 ⟶ 1,346:
which we embed in the following Go program and run it.
{{libheader|WrenGo}}
<syntaxhighlight lang="go">/* environment_variablesEnvironment_variables.go */
package main
 
Line 1,318 ⟶ 1,363:
func main() {
vm := wren.NewVM()
fileName := "environment_variablesEnvironment_variables.wren"
methodMap := wren.MethodMap{"static variable(_)": getEnvironVariable}
classMap := wren.ClassMap{"Environ": wren.NewClass(nil, nil, methodMap)}
890

edits