1
0
Fork 0
forked from fun/fun

Added new opcode OP_ENV to provide an env() function to get environment variables from your OS.

This commit is contained in:
Johannes Findeisen 2025-09-27 10:06:04 +02:00
commit 4345fc6f0c
6 changed files with 47 additions and 3 deletions

18
examples/os_env.fun Normal file
View 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()