Added new opcode OP_ENV to provide an env() function to get environment variables from your OS.
This commit is contained in:
parent
f3b979c07f
commit
4345fc6f0c
6 changed files with 47 additions and 3 deletions
18
examples/os_env.fun
Normal file
18
examples/os_env.fun
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env fun
|
||||
|
||||
// Environment variables via env(name):
|
||||
// - Returns the value as a string.
|
||||
// - If the variable is not set, returns an empty string.
|
||||
|
||||
print("HOME=" + env("HOME"))
|
||||
print("SHELL=" + env("SHELL"))
|
||||
print("FUN_NOT_SET=" + env("FUN_NOT_SET"))
|
||||
|
||||
// You can use it in scripts, e.g.:
|
||||
fun greet()
|
||||
user = env("USER")
|
||||
if user == ""
|
||||
print("Hello, mysterious friend!")
|
||||
else
|
||||
print("Hello, " + user + "!")
|
||||
greet()
|
||||
Loading…
Add table
Add a link
Reference in a new issue